json_explode(«var» «json data»)
This function de-serialises a valid JSON string into an assign variable structure with the provided name.
JSON object names are converted into valid assign variable names by replacing all non-alphanumeric characters with the underscore character. JSON string values are loaded as-is (up to any embedded Unicode NUL character); JSON numeric values are converted subject to set_floating_point_math and set_floating_point_precision; JSON true and false boolean values are converted to 1 and 0 respectively; and JSON null values are converted to an empty string.
If the function fails, the result variable is not modified and a descriptive error string is available from the json_error function.
1 | The function succeeded. |
«empty» | The function failed. |
@ json = [ \ { \ "name": "Jack (\"Bee\") Nimble", \ "format": { \ "type": "rect", \ "width": 1920, \ "height": 1080, \ "interlace": false, \ "frame rate": 24 \ } \ }] if (json_explode(foo $json)) { echo $foo[format][width] } else { echo JSON parse error: $json_error() }