--- JSON-XS/README 2007/07/02 08:06:48 1.15 +++ JSON-XS/README 2007/08/27 02:03:23 1.17 @@ -242,6 +242,34 @@ {"key": "value"} + $json = $json->relaxed ([$enable]) + If $enable is true (or missing), then "decode" will accept some + extensions to normal JSON syntax (see below). "encode" will not be + affected in anyway. *Be aware that this option makes you accept + invalid JSON texts as if they were valid!*. I suggest only to use + this option to parse application-specific files written by humans + (configuration files, resource files etc.) + + If $enable is false (the default), then "decode" will only accept + valid JSON texts. + + Currently accepted extensions are: + + * list items can have an end-comma + JSON *separates* array elements and key-value pairs with commas. + This can be annoying if you write JSON texts manually and want + to be able to quickly append elements, so this extension accepts + comma at the end of such items not just between them: + + [ + 1, + 2, <- this comma not normally allowed + ] + { + "k1": "v1", + "k2": "v2", <- this comma not normally allowed + } + $json = $json->canonical ([$enable]) If $enable is true (or missing), then the "encode" method will output JSON objects by sorting their keys. This is adding a @@ -504,12 +532,25 @@ so no manual decoding is necessary. number - A JSON number becomes either an integer or numeric (floating point) - scalar in perl, depending on its range and any fractional parts. On - the Perl level, there is no difference between those as Perl handles - all the conversion details, but an integer may take slightly less - memory and might represent more values exactly than (floating point) - numbers. + A JSON number becomes either an integer, numeric (floating point) or + string scalar in perl, depending on its range and any fractional + parts. On the Perl level, there is no difference between those as + Perl handles all the conversion details, but an integer may take + slightly less memory and might represent more values exactly than + (floating point) numbers. + + If the number consists of digits only, JSON::XS will try to + represent it as an integer value. If that fails, it will try to + represent it as a numeric (floating point) value if that is possible + without loss of precision. Otherwise it will preserve the number as + a string value. + + Numbers containing a fractional or exponential part will always be + represented as numeric (floating point) values, possibly at a loss + of precision. + + This might create round-tripping problems as numbers might become + strings, but as Perl is typeless there is no other way to do it. true, false These JSON atoms become "JSON::XS::true" and "JSON::XS::false",