Decode JSON safely in PHP
Parse JSON with exceptions on error and a depth limit, instead of silently getting null.
Loading snippets…
137 snippets
Parse JSON with exceptions on error and a depth limit, instead of silently getting null.
Compute cumulative sums per group without self-joins using SUM() OVER (PARTITION BY ... ORDER BY ...).
Retry a failing promise-returning function with growing, jittered delays and a retry predicate.
Re-run a flaky function a limited number of times with growing delays, only for chosen exception types.
Model success and failure as a discriminated union so callers must handle both cases.
Serve modern formats and the right image size per device, with explicit dimensions to prevent layout shift.
Use CSS Grid with repeat(auto-fit, minmax()) so cards wrap automatically at any width.
Connect with PDO in exception mode and bind parameters to prevent SQL injection.
Iterate cursor-paginated API results with for await, loading pages lazily and stopping early when needed.
Clip long text to one line or N lines with an ellipsis using text-overflow and line-clamp.
Page through large tables quickly and stably by filtering on the last seen sort key.
Replace "as any" on parsed JSON with small type guards that check shape at runtime.