… | |
… | |
91 | This function call is functionally identical to: |
91 | This function call is functionally identical to: |
92 | |
92 | |
93 | $perl_scalar = JSON::XS->new->utf8->decode ($json_text) |
93 | $perl_scalar = JSON::XS->new->utf8->decode ($json_text) |
94 | |
94 | |
95 | except being faster. |
95 | except being faster. |
|
|
96 | |
|
|
97 | $is_boolean = JSON::XS::is_bool $scalar |
|
|
98 | Returns true if the passed scalar represents either JSON::XS::true |
|
|
99 | or JSON::XS::false, two constants that act like 1 and 0, |
|
|
100 | respectively and are used to represent JSON "true" and "false" |
|
|
101 | values in Perl. |
|
|
102 | |
|
|
103 | See MAPPING, below, for more information on how JSON values are |
|
|
104 | mapped to Perl. |
96 | |
105 | |
97 | OBJECT-ORIENTED INTERFACE |
106 | OBJECT-ORIENTED INTERFACE |
98 | The object oriented interface lets you configure your own encoding or |
107 | The object oriented interface lets you configure your own encoding or |
99 | decoding style, within the limits of supported formats. |
108 | decoding style, within the limits of supported formats. |
100 | |
109 | |
… | |
… | |
379 | all the conversion details, but an integer may take slightly less |
388 | all the conversion details, but an integer may take slightly less |
380 | memory and might represent more values exactly than (floating point) |
389 | memory and might represent more values exactly than (floating point) |
381 | numbers. |
390 | numbers. |
382 | |
391 | |
383 | true, false |
392 | true, false |
384 | These JSON atoms become 0, 1, respectively. Information is lost in |
393 | These JSON atoms become "JSON::XS::true" and "JSON::XS::false", |
385 | this process. Future versions might represent those values |
394 | respectively. They are overloaded to act almost exactly like the |
386 | differently, but they will be guarenteed to act like these integers |
395 | numbers 1 and 0. You can check wether a scalar is a JSON boolean by |
387 | would normally in Perl. |
396 | using the "JSON::XS::is_bool" function. |
388 | |
397 | |
389 | null |
398 | null |
390 | A JSON null atom becomes "undef" in Perl. |
399 | A JSON null atom becomes "undef" in Perl. |
391 | |
400 | |
392 | PERL -> JSON |
401 | PERL -> JSON |
… | |
… | |
416 | can also use "JSON::XS::false" and "JSON::XS::true" to improve |
425 | can also use "JSON::XS::false" and "JSON::XS::true" to improve |
417 | readability. |
426 | readability. |
418 | |
427 | |
419 | to_json [\0,JSON::XS::true] # yields [false,true] |
428 | to_json [\0,JSON::XS::true] # yields [false,true] |
420 | |
429 | |
|
|
430 | JSON::XS::true, JSON::XS::false |
|
|
431 | These special values become JSON true and JSON false values, |
|
|
432 | respectively. You cna alos use "\1" and "\0" directly if you want. |
|
|
433 | |
421 | blessed objects |
434 | blessed objects |
422 | Blessed objects are not allowed. JSON::XS currently tries to encode |
435 | Blessed objects are not allowed. JSON::XS currently tries to encode |
423 | their underlying representation (hash- or arrayref), but this |
436 | their underlying representation (hash- or arrayref), but this |
424 | behaviour might change in future versions. |
437 | behaviour might change in future versions. |
425 | |
438 | |
… | |
… | |
644 | |
657 | |
645 | And last but least, something else could bomb you that I forgot to think |
658 | And last but least, something else could bomb you that I forgot to think |
646 | of. In that case, you get to keep the pieces. I am always open for |
659 | of. In that case, you get to keep the pieces. I am always open for |
647 | hints, though... |
660 | hints, though... |
648 | |
661 | |
|
|
662 | If you are using JSON::XS to return packets to consumption by javascript |
|
|
663 | scripts in a browser you should have a look at |
|
|
664 | <http://jpsykes.com/47/practical-csrf-and-json-security> to see wether |
|
|
665 | you are vulnerable to some common attack vectors (which really are |
|
|
666 | browser design bugs, but it is still you who will have to deal with it, |
|
|
667 | as major browser developers care only for features, not about doing |
|
|
668 | security right). |
|
|
669 | |
649 | BUGS |
670 | BUGS |
650 | While the goal of this module is to be correct, that unfortunately does |
671 | While the goal of this module is to be correct, that unfortunately does |
651 | not mean its bug-free, only that I think its design is bug-free. It is |
672 | not mean its bug-free, only that I think its design is bug-free. It is |
652 | still relatively early in its development. If you keep reporting bugs |
673 | still relatively early in its development. If you keep reporting bugs |
653 | they will be fixed swiftly, though. |
674 | they will be fixed swiftly, though. |