Decoding JSON

Decoding, Depth Limits and Associative Arrays

json_decode($json, $associative = null, $depth = 512, $flags = 0) returns stdClass objects, or associative arrays when the second argument is true.

Objects, arrays, big integers and the depth limitPHP
<?php
$json = '{"special-sku":"BK-PHP-01","isbn":12345678901234567890,"dims":{}}';
$o = json_decode($json);                                   // objects become stdClass
$a = json_decode($json, true, 16, JSON_BIGINT_AS_STRING);  // objects become arrays
echo $o->{'special-sku'}, ' ', $o->isbn, ' ', $a['isbn'], ' ', json_encode($a['dims']), "\n";
echo json_encode([json_decode('[[["deep"]]]', true, 3), json_last_error_msg()]), "\n";
Output
BK-PHP-01 1.2345678901235E+19 12345678901234567890 []
[null,"Maximum stack depth exceeded"]

Arrays spare you the {'special-sku'} syntax, but {} comes back as []. An integer larger than PHP_INT_MAX silently becomes a float, so use JSON_BIGINT_AS_STRING for external IDs. The depth must exceed the nesting ([[["deep"]]] needs 4).