Check Valid JSON Data

and like us on FB

The following functions will check for and return valid JSON. Generally, json_last_error is best used to return the last error (if any) occurred during the last JSON encoding/decoding. The json_last_error function returns an integer but should be checked by way of the following constants:

Check Valid JSON Data

JSON Error Codes. Source: PHP Manual.

The following will decode JSON and return either the resulting array or false (if the JSON returned an error).

For debugging purposes, it’s handy to know the precise error causing grief.

Source: Stackoverflow/Madan Sapkota.