PHP json_decode() converts a JSON string into an object or associative array.
Code examples
$data = json_decode($json, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new RuntimeException(json_last_error_msg());
}
Use exceptions in newer code:
$data = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
Common errors
JSON does not allow trailing commas, comments, or unquoted keys. PHP also expects valid UTF-8.
Related tool
Try the PHP JSON Formatter Online.