… | |
… | |
81 | |
81 | |
82 | package JSON::XS; |
82 | package JSON::XS; |
83 | |
83 | |
84 | use strict; |
84 | use strict; |
85 | |
85 | |
86 | our $VERSION = '1.43'; |
86 | our $VERSION = '1.5'; |
87 | our @ISA = qw(Exporter); |
87 | our @ISA = qw(Exporter); |
88 | |
88 | |
89 | our @EXPORT = qw(to_json from_json); |
89 | our @EXPORT = qw(to_json from_json); |
90 | |
90 | |
91 | use Exporter; |
91 | use Exporter; |
… | |
… | |
277 | This setting has no effect when decoding JSON texts. |
277 | This setting has no effect when decoding JSON texts. |
278 | |
278 | |
279 | Example, space_before and indent disabled, space_after enabled: |
279 | Example, space_before and indent disabled, space_after enabled: |
280 | |
280 | |
281 | {"key": "value"} |
281 | {"key": "value"} |
|
|
282 | |
|
|
283 | =item $json = $json->relaxed ([$enable]) |
|
|
284 | |
|
|
285 | If C<$enable> is true (or missing), then C<decode> will accept some |
|
|
286 | extensions to normal JSON syntax (see below). C<encode> will not be |
|
|
287 | affected in anyway. I<Be aware that this option makes you accept invalid |
|
|
288 | JSON texts as if they were valid!>. I suggest only to use this option to |
|
|
289 | parse application-specific files written by humans (configuration files, |
|
|
290 | resource files etc.) |
|
|
291 | |
|
|
292 | If C<$enable> is false (the default), then C<decode> will only accept |
|
|
293 | valid JSON texts. |
|
|
294 | |
|
|
295 | Currently accepted extensions are: |
|
|
296 | |
|
|
297 | =over 4 |
|
|
298 | |
|
|
299 | =item * list items can have an end-comma |
|
|
300 | |
|
|
301 | JSON I<separates> array elements and key-value pairs with commas. This |
|
|
302 | can be annoying if you write JSON texts manually and want to be able to |
|
|
303 | quickly append elements, so this extension accepts comma at the end of |
|
|
304 | such items not just between them: |
|
|
305 | |
|
|
306 | [ |
|
|
307 | 1, |
|
|
308 | 2, <- this comma not normally allowed |
|
|
309 | ] |
|
|
310 | { |
|
|
311 | "k1": "v1", |
|
|
312 | "k2": "v2", <- this comma not normally allowed |
|
|
313 | } |
|
|
314 | |
|
|
315 | =back |
282 | |
316 | |
283 | =item $json = $json->canonical ([$enable]) |
317 | =item $json = $json->canonical ([$enable]) |
284 | |
318 | |
285 | If C<$enable> is true (or missing), then the C<encode> method will output JSON objects |
319 | If C<$enable> is true (or missing), then the C<encode> method will output JSON objects |
286 | by sorting their keys. This is adding a comparatively high overhead. |
320 | by sorting their keys. This is adding a comparatively high overhead. |