<?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; } }
You have javascript disabled. You will not be able to edit any code.