Decode bad 'JSON' in PHP
PHP Perl
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Flamework-JSON - Decode bad 'JSON' in PHP

The built-in PHP JSON decoder is very strict, and will not accept things which are fairly common in the wild:

  • unquoted keys, e.g. {foo: 1}
  • single-quoted strings, e.g. {"foo": 'bar'}
  • escaped single quoted, e.g. {"foo": "b'ar"}
  • empty array elements, e.g. [1,,2]

This library allows you to decode JavaScript objects as if they were valid JSON.



$obj = json_decode_loose($str);

If you're using Flamework, just drop lib_json.php into your include folder.


If you have perl's Test::Harness installed (you almost certainly do), you can run the tests using:

prove --exec 'php' t/*.t