1--TEST-- 2JSON (http://www.crockford.com/JSON/JSON_checker/test/fail*.json) 3--FILE-- 4<?php 5 6$tests = array( 7 '"A JSON payload should be an object or array, not a string."', 8 '["Unclosed array"', 9 '{unquoted_key: "keys must be quoted}', 10 '["extra comma",]', 11 '["double extra comma",,]', 12 '[ , "<-- missing value"]', 13 '["Comma after the close"],', 14 '["Extra close"]]', 15 '{"Extra comma": true,}', 16 '{"Extra value after close": true} "misplaced quoted value"', 17 '{"Illegal expression": 1 + 2}', 18 '{"Illegal invocation": alert()}', 19 '{"Numbers cannot have leading zeroes": 013}', 20 '{"Numbers cannot be hex": 0x14}', 21 '["Illegal backslash escape: \\x15"]', 22 '["Illegal backslash escape: \\\'"]', 23 '["Illegal backslash escape: \\017"]', 24 '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]', 25 '{"Missing colon" null}', 26 '{"Double colon":: null}', 27 '{"Comma instead of colon", null}', 28 '["Colon instead of comma": false]', 29 '["Bad value", truth]', 30 "['single quote']" 31); 32 33foreach ($tests as $test) { 34 echo 'Testing: ' . $test . "\n"; 35 echo "AS OBJECT\n"; 36 var_dump(json_decode($test)); 37 echo "AS ARRAY\n"; 38 var_dump(json_decode($test, true)); 39} 40 41?> 42--EXPECT-- 43Testing: "A JSON payload should be an object or array, not a string." 44AS OBJECT 45string(58) "A JSON payload should be an object or array, not a string." 46AS ARRAY 47string(58) "A JSON payload should be an object or array, not a string." 48Testing: ["Unclosed array" 49AS OBJECT 50NULL 51AS ARRAY 52NULL 53Testing: {unquoted_key: "keys must be quoted} 54AS OBJECT 55NULL 56AS ARRAY 57NULL 58Testing: ["extra comma",] 59AS OBJECT 60NULL 61AS ARRAY 62NULL 63Testing: ["double extra comma",,] 64AS OBJECT 65NULL 66AS ARRAY 67NULL 68Testing: [ , "<-- missing value"] 69AS OBJECT 70NULL 71AS ARRAY 72NULL 73Testing: ["Comma after the close"], 74AS OBJECT 75NULL 76AS ARRAY 77NULL 78Testing: ["Extra close"]] 79AS OBJECT 80NULL 81AS ARRAY 82NULL 83Testing: {"Extra comma": true,} 84AS OBJECT 85NULL 86AS ARRAY 87NULL 88Testing: {"Extra value after close": true} "misplaced quoted value" 89AS OBJECT 90NULL 91AS ARRAY 92NULL 93Testing: {"Illegal expression": 1 + 2} 94AS OBJECT 95NULL 96AS ARRAY 97NULL 98Testing: {"Illegal invocation": alert()} 99AS OBJECT 100NULL 101AS ARRAY 102NULL 103Testing: {"Numbers cannot have leading zeroes": 013} 104AS OBJECT 105NULL 106AS ARRAY 107NULL 108Testing: {"Numbers cannot be hex": 0x14} 109AS OBJECT 110NULL 111AS ARRAY 112NULL 113Testing: ["Illegal backslash escape: \x15"] 114AS OBJECT 115NULL 116AS ARRAY 117NULL 118Testing: ["Illegal backslash escape: \'"] 119AS OBJECT 120NULL 121AS ARRAY 122NULL 123Testing: ["Illegal backslash escape: \017"] 124AS OBJECT 125NULL 126AS ARRAY 127NULL 128Testing: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] 129AS OBJECT 130NULL 131AS ARRAY 132NULL 133Testing: {"Missing colon" null} 134AS OBJECT 135NULL 136AS ARRAY 137NULL 138Testing: {"Double colon":: null} 139AS OBJECT 140NULL 141AS ARRAY 142NULL 143Testing: {"Comma instead of colon", null} 144AS OBJECT 145NULL 146AS ARRAY 147NULL 148Testing: ["Colon instead of comma": false] 149AS OBJECT 150NULL 151AS ARRAY 152NULL 153Testing: ["Bad value", truth] 154AS OBJECT 155NULL 156AS ARRAY 157NULL 158Testing: ['single quote'] 159AS OBJECT 160NULL 161AS ARRAY 162NULL 163