3v4l.org

run code in 500+ PHP versions simultaneously
<?php $fixtures = [ // Not valid 'foo', '{foo: bar}', "'{'foo': 'bar'}", '{...}', // Valid '"foo"', '1', '{"foo": "bar"}', ]; foreach ($fixtures as $string) { if (json_validate($string)) { echo sprintf('YES, >%s< is a valid JSON string', $string).PHP_EOL; echo 'decoded: '. var_export(json_decode($string), true).PHP_EOL; } else { echo sprintf('NO, >%s< is NOT a valid JSON string: %s', $string, json_last_error_msg()). PHP_EOL; } }
Output for 8.3.1 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
NO, >foo< is NOT a valid JSON string: Syntax error NO, >{foo: bar}< is NOT a valid JSON string: Syntax error NO, >'{'foo': 'bar'}< is NOT a valid JSON string: Syntax error NO, >{...}< is NOT a valid JSON string: Syntax error YES, >"foo"< is a valid JSON string decoded: 'foo' YES, >1< is a valid JSON string decoded: 1 YES, >{"foo": "bar"}< is a valid JSON string decoded: (object) array( 'foo' => 'bar', )
Output for 8.1.27 - 8.1.34, 8.2.14 - 8.2.30
Fatal error: Uncaught Error: Call to undefined function json_validate() in /in/EIUPB:17 Stack trace: #0 {main} thrown in /in/EIUPB on line 17
Process exited with code 255.

preferences:
69.98 ms | 858 KiB | 4 Q