Parse JSON with a fallback value returned if parsing fails.
Code
Utilities$result = json_decode($jsonStr);
json_encode($result !== null ? $result : json_decode($fallback));Parameters
JSON string to parse.
Fallback value if parsing fails (as JSON).
Server
More PHP Snippets
Minify JSON
Remove whitespace from JSON to minimize file size and bandwidth.
Prettify JSON
Format JSON with proper indentation for improved readability and debugging.
Array Difference
Find elements in the first array that are not present in the second array.
Array Frequencies
Count how many times each value appears in an array and return a frequency map.
Array Head
Get the first n elements of an array.
Array Intersection
Find common elements that exist in both arrays.