Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php $json = '{"name":"Alice","age":30,"tags":["admin"]}'; // Default: stdClass object $obj = json_decode($json); echo $obj->name; // "Alice" // As associative array (recommended) $arr = json_decode($json, true); echo $arr["name"]; // "Alice" // Error handling $result = json_decode($badJson, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidArgumentException("Invalid JSON: " . json_last_error_msg()); }
Result
Open