… | |
… | |
4 | |
4 | |
5 | #include "assert.h" |
5 | #include "assert.h" |
6 | #include "string.h" |
6 | #include "string.h" |
7 | #include "stdlib.h" |
7 | #include "stdlib.h" |
8 | |
8 | |
9 | #define F_ASCII 0x00000001 |
9 | #define F_ASCII 0x00000001UL |
10 | #define F_UTF8 0x00000002 |
10 | #define F_UTF8 0x00000002UL |
11 | #define F_INDENT 0x00000004 |
11 | #define F_INDENT 0x00000004UL |
12 | #define F_CANONICAL 0x00000008 |
12 | #define F_CANONICAL 0x00000008UL |
13 | #define F_SPACE_BEFORE 0x00000010 |
13 | #define F_SPACE_BEFORE 0x00000010UL |
14 | #define F_SPACE_AFTER 0x00000020 |
14 | #define F_SPACE_AFTER 0x00000020UL |
15 | #define F_ALLOW_NONREF 0x00000080 |
15 | #define F_ALLOW_NONREF 0x00000080UL |
16 | #define F_SHRINK 0x00000100 |
16 | #define F_SHRINK 0x00000100UL |
|
|
17 | #define F_MAXDEPTH 0xf8000000UL |
|
|
18 | #define S_MAXDEPTH 27 |
17 | |
19 | |
18 | // F_SKIPINVALID? |
20 | #define DEC_DEPTH(flags) (1UL << ((flags & F_MAXDEPTH) >> S_MAXDEPTH)) |
19 | // F_EXECCODEREF? |
21 | |
20 | // F_SELFCONVERT? <=> { &__class__ => } |
22 | // F_SELFCONVERT? <=> to_json/toJson |
|
|
23 | // F_BLESSED? <=> { $__class__$ => } |
21 | |
24 | |
22 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
25 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
23 | #define F_DEFAULT 0 |
26 | #define F_DEFAULT (12UL << S_MAXDEPTH) |
24 | |
27 | |
25 | #define INIT_SIZE 32 // initial scalar size to be allocated |
28 | #define INIT_SIZE 32 // initial scalar size to be allocated |
26 | #define INDENT_STEP 3 // spaces per indentation level |
29 | #define INDENT_STEP 3 // spaces per indentation level |
27 | |
30 | |
28 | #define UTF8_MAX_LEN 11 // for perls UTF-X: max. number of octets per character |
31 | #define UTF8_MAX_LEN 11 // for perls UTF-X: max. number of octets per character |
… | |
… | |
73 | { |
76 | { |
74 | *clen = 2; |
77 | *clen = 2; |
75 | return ((s[0] & 0x1f) << 6) | (s[1] & 0x3f); |
78 | return ((s[0] & 0x1f) << 6) | (s[1] & 0x3f); |
76 | } |
79 | } |
77 | else |
80 | else |
|
|
81 | { |
|
|
82 | *clen = (STRLEN)-1; |
78 | return (UV)-1; |
83 | return (UV)-1; |
|
|
84 | } |
79 | } |
85 | } |
80 | |
86 | |
81 | ///////////////////////////////////////////////////////////////////////////// |
87 | ///////////////////////////////////////////////////////////////////////////// |
82 | // encoder |
88 | // encoder |
83 | |
89 | |
… | |
… | |
85 | typedef struct |
91 | typedef struct |
86 | { |
92 | { |
87 | char *cur; // SvPVX (sv) + current output position |
93 | char *cur; // SvPVX (sv) + current output position |
88 | char *end; // SvEND (sv) |
94 | char *end; // SvEND (sv) |
89 | SV *sv; // result scalar |
95 | SV *sv; // result scalar |
90 | UV flags; // F_* |
96 | U32 flags; // F_* |
91 | int indent; // indentation level |
97 | U32 indent; // indentation level |
92 | int max_depth; // max. recursion level |
98 | U32 maxdepth; // max. indentation/recursion level |
93 | } enc_t; |
99 | } enc_t; |
94 | |
100 | |
95 | static void |
101 | static void |
96 | need (enc_t *enc, STRLEN len) |
102 | need (enc_t *enc, STRLEN len) |
97 | { |
103 | { |
… | |
… | |
265 | static void |
271 | static void |
266 | encode_av (enc_t *enc, AV *av) |
272 | encode_av (enc_t *enc, AV *av) |
267 | { |
273 | { |
268 | int i, len = av_len (av); |
274 | int i, len = av_len (av); |
269 | |
275 | |
|
|
276 | if (enc->indent >= enc->maxdepth) |
|
|
277 | croak ("data structure too deep (hit recursion limit)"); |
|
|
278 | |
270 | encode_ch (enc, '['); encode_nl (enc); |
279 | encode_ch (enc, '['); encode_nl (enc); |
271 | ++enc->indent; |
280 | ++enc->indent; |
272 | |
281 | |
273 | for (i = 0; i <= len; ++i) |
282 | for (i = 0; i <= len; ++i) |
274 | { |
283 | { |
… | |
… | |
339 | |
348 | |
340 | static void |
349 | static void |
341 | encode_hv (enc_t *enc, HV *hv) |
350 | encode_hv (enc_t *enc, HV *hv) |
342 | { |
351 | { |
343 | int count, i; |
352 | int count, i; |
|
|
353 | |
|
|
354 | if (enc->indent >= enc->maxdepth) |
|
|
355 | croak ("data structure too deep (hit recursion limit)"); |
344 | |
356 | |
345 | encode_ch (enc, '{'); encode_nl (enc); ++enc->indent; |
357 | encode_ch (enc, '{'); encode_nl (enc); ++enc->indent; |
346 | |
358 | |
347 | if ((count = hv_iterinit (hv))) |
359 | if ((count = hv_iterinit (hv))) |
348 | { |
360 | { |
… | |
… | |
417 | } |
429 | } |
418 | |
430 | |
419 | --enc->indent; encode_indent (enc); encode_ch (enc, '}'); |
431 | --enc->indent; encode_indent (enc); encode_ch (enc, '}'); |
420 | } |
432 | } |
421 | |
433 | |
|
|
434 | // encode objects, arrays and special \0=false and \1=true values. |
|
|
435 | static void |
|
|
436 | encode_rv (enc_t *enc, SV *sv) |
|
|
437 | { |
|
|
438 | SvGETMAGIC (sv); |
|
|
439 | |
|
|
440 | svtype svt = SvTYPE (sv); |
|
|
441 | |
|
|
442 | if (svt == SVt_PVHV) |
|
|
443 | encode_hv (enc, (HV *)sv); |
|
|
444 | else if (svt == SVt_PVAV) |
|
|
445 | encode_av (enc, (AV *)sv); |
|
|
446 | else if (svt < SVt_PVAV) |
|
|
447 | { |
|
|
448 | if (SvNIOK (sv) && SvIV (sv) == 0) |
|
|
449 | encode_str (enc, "false", 5, 0); |
|
|
450 | else if (SvNIOK (sv) && SvIV (sv) == 1) |
|
|
451 | encode_str (enc, "true", 4, 0); |
|
|
452 | else |
|
|
453 | croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", |
|
|
454 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
|
|
455 | } |
|
|
456 | else |
|
|
457 | croak ("encountered %s, but JSON can only represent references to arrays or hashes", |
|
|
458 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
|
|
459 | } |
|
|
460 | |
422 | static void |
461 | static void |
423 | encode_sv (enc_t *enc, SV *sv) |
462 | encode_sv (enc_t *enc, SV *sv) |
424 | { |
463 | { |
425 | SvGETMAGIC (sv); |
464 | SvGETMAGIC (sv); |
426 | |
465 | |
… | |
… | |
445 | SvIsUV(sv) |
484 | SvIsUV(sv) |
446 | ? snprintf (enc->cur, 64, "%"UVuf, (UV)SvUVX (sv)) |
485 | ? snprintf (enc->cur, 64, "%"UVuf, (UV)SvUVX (sv)) |
447 | : snprintf (enc->cur, 64, "%"IVdf, (IV)SvIVX (sv)); |
486 | : snprintf (enc->cur, 64, "%"IVdf, (IV)SvIVX (sv)); |
448 | } |
487 | } |
449 | else if (SvROK (sv)) |
488 | else if (SvROK (sv)) |
450 | { |
489 | encode_rv (enc, SvRV (sv)); |
451 | SV *rv = SvRV (sv); |
|
|
452 | |
|
|
453 | if (enc->indent >= enc->max_depth) |
|
|
454 | croak ("data structure too deep (hit recursion limit)"); |
|
|
455 | |
|
|
456 | switch (SvTYPE (rv)) |
|
|
457 | { |
|
|
458 | case SVt_PVAV: encode_av (enc, (AV *)rv); break; |
|
|
459 | case SVt_PVHV: encode_hv (enc, (HV *)rv); break; |
|
|
460 | |
|
|
461 | default: |
|
|
462 | croak ("encountered %s, but JSON can only represent references to arrays or hashes", |
|
|
463 | SvPV_nolen (sv)); |
|
|
464 | } |
|
|
465 | } |
|
|
466 | else if (!SvOK (sv)) |
490 | else if (!SvOK (sv)) |
467 | encode_str (enc, "null", 4, 0); |
491 | encode_str (enc, "null", 4, 0); |
468 | else |
492 | else |
469 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
493 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
470 | SvPV_nolen (sv), SvFLAGS (sv)); |
494 | SvPV_nolen (sv), SvFLAGS (sv)); |
471 | } |
495 | } |
472 | |
496 | |
473 | static SV * |
497 | static SV * |
474 | encode_json (SV *scalar, UV flags) |
498 | encode_json (SV *scalar, U32 flags) |
475 | { |
499 | { |
476 | if (!(flags & F_ALLOW_NONREF) && !SvROK (scalar)) |
500 | if (!(flags & F_ALLOW_NONREF) && !SvROK (scalar)) |
477 | croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); |
501 | croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); |
478 | |
502 | |
479 | enc_t enc; |
503 | enc_t enc; |
480 | enc.flags = flags; |
504 | enc.flags = flags; |
481 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
505 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
482 | enc.cur = SvPVX (enc.sv); |
506 | enc.cur = SvPVX (enc.sv); |
483 | enc.end = SvEND (enc.sv); |
507 | enc.end = SvEND (enc.sv); |
484 | enc.indent = 0; |
508 | enc.indent = 0; |
485 | enc.max_depth = 0x7fffffffUL; |
509 | enc.maxdepth = DEC_DEPTH (flags); |
486 | |
510 | |
487 | SvPOK_only (enc.sv); |
511 | SvPOK_only (enc.sv); |
488 | encode_sv (&enc, scalar); |
512 | encode_sv (&enc, scalar); |
489 | |
513 | |
490 | if (!(flags & (F_ASCII | F_UTF8))) |
514 | if (!(flags & (F_ASCII | F_UTF8))) |
… | |
… | |
505 | typedef struct |
529 | typedef struct |
506 | { |
530 | { |
507 | char *cur; // current parser pointer |
531 | char *cur; // current parser pointer |
508 | char *end; // end of input string |
532 | char *end; // end of input string |
509 | const char *err; // parse error, if != 0 |
533 | const char *err; // parse error, if != 0 |
510 | UV flags; // F_* |
534 | U32 flags; // F_* |
|
|
535 | U32 depth; // recursion depth |
|
|
536 | U32 maxdepth; // recursion depth limit |
511 | } dec_t; |
537 | } dec_t; |
512 | |
538 | |
513 | static void |
539 | static void |
514 | decode_ws (dec_t *dec) |
540 | decode_ws (dec_t *dec) |
515 | { |
541 | { |
… | |
… | |
524 | ++dec->cur; |
550 | ++dec->cur; |
525 | } |
551 | } |
526 | } |
552 | } |
527 | |
553 | |
528 | #define ERR(reason) SB dec->err = reason; goto fail; SE |
554 | #define ERR(reason) SB dec->err = reason; goto fail; SE |
|
|
555 | |
529 | #define EXPECT_CH(ch) SB \ |
556 | #define EXPECT_CH(ch) SB \ |
530 | if (*dec->cur != ch) \ |
557 | if (*dec->cur != ch) \ |
531 | ERR (# ch " expected"); \ |
558 | ERR (# ch " expected"); \ |
532 | ++dec->cur; \ |
559 | ++dec->cur; \ |
533 | SE |
560 | SE |
|
|
561 | |
|
|
562 | #define DEC_INC_DEPTH if (++dec->depth > dec->maxdepth) ERR ("json datastructure exceeds maximum nesting level (set a higher max_depth)") |
|
|
563 | #define DEC_DEC_DEPTH --dec->depth |
534 | |
564 | |
535 | static SV *decode_sv (dec_t *dec); |
565 | static SV *decode_sv (dec_t *dec); |
536 | |
566 | |
537 | static signed char decode_hexdigit[256]; |
567 | static signed char decode_hexdigit[256]; |
538 | |
568 | |
… | |
… | |
648 | UV uch = decode_utf8 (dec->cur, dec->end - dec->cur, &clen); |
678 | UV uch = decode_utf8 (dec->cur, dec->end - dec->cur, &clen); |
649 | if (clen == (STRLEN)-1) |
679 | if (clen == (STRLEN)-1) |
650 | ERR ("malformed UTF-8 character in JSON string"); |
680 | ERR ("malformed UTF-8 character in JSON string"); |
651 | |
681 | |
652 | do |
682 | do |
653 | { |
|
|
654 | *cur++ = *dec->cur++; |
683 | *cur++ = *dec->cur++; |
655 | } |
|
|
656 | while (--clen); |
684 | while (--clen); |
657 | |
685 | |
658 | utf8 = 1; |
686 | utf8 = 1; |
659 | } |
687 | } |
660 | else if (!ch) |
|
|
661 | ERR ("unexpected end of string while parsing json string"); |
|
|
662 | else |
688 | else |
|
|
689 | { |
|
|
690 | --dec->cur; |
|
|
691 | |
|
|
692 | if (!ch) |
|
|
693 | ERR ("unexpected end of string while parsing json string"); |
|
|
694 | else |
663 | ERR ("invalid character encountered"); |
695 | ERR ("invalid character encountered while parsing json string"); |
664 | |
696 | } |
665 | } |
697 | } |
666 | while (cur < buf + SHORT_STRING_LEN); |
698 | while (cur < buf + SHORT_STRING_LEN); |
667 | |
699 | |
668 | STRLEN len = cur - buf; |
700 | STRLEN len = cur - buf; |
669 | |
701 | |
… | |
… | |
782 | static SV * |
814 | static SV * |
783 | decode_av (dec_t *dec) |
815 | decode_av (dec_t *dec) |
784 | { |
816 | { |
785 | AV *av = newAV (); |
817 | AV *av = newAV (); |
786 | |
818 | |
|
|
819 | DEC_INC_DEPTH; |
787 | decode_ws (dec); |
820 | decode_ws (dec); |
|
|
821 | |
788 | if (*dec->cur == ']') |
822 | if (*dec->cur == ']') |
789 | ++dec->cur; |
823 | ++dec->cur; |
790 | else |
824 | else |
791 | for (;;) |
825 | for (;;) |
792 | { |
826 | { |
… | |
… | |
810 | ERR (", or ] expected while parsing array"); |
844 | ERR (", or ] expected while parsing array"); |
811 | |
845 | |
812 | ++dec->cur; |
846 | ++dec->cur; |
813 | } |
847 | } |
814 | |
848 | |
|
|
849 | DEC_DEC_DEPTH; |
815 | return newRV_noinc ((SV *)av); |
850 | return newRV_noinc ((SV *)av); |
816 | |
851 | |
817 | fail: |
852 | fail: |
818 | SvREFCNT_dec (av); |
853 | SvREFCNT_dec (av); |
|
|
854 | DEC_DEC_DEPTH; |
819 | return 0; |
855 | return 0; |
820 | } |
856 | } |
821 | |
857 | |
822 | static SV * |
858 | static SV * |
823 | decode_hv (dec_t *dec) |
859 | decode_hv (dec_t *dec) |
824 | { |
860 | { |
825 | HV *hv = newHV (); |
861 | HV *hv = newHV (); |
826 | |
862 | |
|
|
863 | DEC_INC_DEPTH; |
827 | decode_ws (dec); |
864 | decode_ws (dec); |
|
|
865 | |
828 | if (*dec->cur == '}') |
866 | if (*dec->cur == '}') |
829 | ++dec->cur; |
867 | ++dec->cur; |
830 | else |
868 | else |
831 | for (;;) |
869 | for (;;) |
832 | { |
870 | { |
… | |
… | |
845 | { |
883 | { |
846 | SvREFCNT_dec (key); |
884 | SvREFCNT_dec (key); |
847 | goto fail; |
885 | goto fail; |
848 | } |
886 | } |
849 | |
887 | |
850 | //TODO: optimise |
|
|
851 | hv_store_ent (hv, key, value, 0); |
888 | hv_store_ent (hv, key, value, 0); |
|
|
889 | SvREFCNT_dec (key); |
852 | |
890 | |
853 | decode_ws (dec); |
891 | decode_ws (dec); |
854 | |
892 | |
855 | if (*dec->cur == '}') |
893 | if (*dec->cur == '}') |
856 | { |
894 | { |
… | |
… | |
862 | ERR (", or } expected while parsing object/hash"); |
900 | ERR (", or } expected while parsing object/hash"); |
863 | |
901 | |
864 | ++dec->cur; |
902 | ++dec->cur; |
865 | } |
903 | } |
866 | |
904 | |
|
|
905 | DEC_DEC_DEPTH; |
867 | return newRV_noinc ((SV *)hv); |
906 | return newRV_noinc ((SV *)hv); |
868 | |
907 | |
869 | fail: |
908 | fail: |
870 | SvREFCNT_dec (hv); |
909 | SvREFCNT_dec (hv); |
|
|
910 | DEC_DEC_DEPTH; |
871 | return 0; |
911 | return 0; |
872 | } |
912 | } |
873 | |
913 | |
874 | static SV * |
914 | static SV * |
875 | decode_sv (dec_t *dec) |
915 | decode_sv (dec_t *dec) |
… | |
… | |
927 | fail: |
967 | fail: |
928 | return 0; |
968 | return 0; |
929 | } |
969 | } |
930 | |
970 | |
931 | static SV * |
971 | static SV * |
932 | decode_json (SV *string, UV flags) |
972 | decode_json (SV *string, U32 flags) |
933 | { |
973 | { |
934 | SV *sv; |
974 | SV *sv; |
|
|
975 | |
|
|
976 | SvUPGRADE (string, SVt_PV); |
935 | |
977 | |
936 | if (flags & F_UTF8) |
978 | if (flags & F_UTF8) |
937 | sv_utf8_downgrade (string, 0); |
979 | sv_utf8_downgrade (string, 0); |
938 | else |
980 | else |
939 | sv_utf8_upgrade (string); |
981 | sv_utf8_upgrade (string); |
940 | |
982 | |
941 | SvGROW (string, SvCUR (string) + 1); // should basically be a NOP |
983 | SvGROW (string, SvCUR (string) + 1); // should basically be a NOP |
942 | |
984 | |
943 | dec_t dec; |
985 | dec_t dec; |
944 | dec.flags = flags; |
986 | dec.flags = flags; |
945 | dec.cur = SvPVX (string); |
987 | dec.cur = SvPVX (string); |
946 | dec.end = SvEND (string); |
988 | dec.end = SvEND (string); |
947 | dec.err = 0; |
989 | dec.err = 0; |
|
|
990 | dec.depth = 0; |
|
|
991 | dec.maxdepth = DEC_DEPTH (dec.flags); |
948 | |
992 | |
|
|
993 | *dec.end = 0; // this should basically be a nop, too, but make sure its there |
949 | sv = decode_sv (&dec); |
994 | sv = decode_sv (&dec); |
950 | |
995 | |
951 | if (!sv) |
996 | if (!sv) |
952 | { |
997 | { |
953 | IV offset = dec.flags & F_UTF8 |
998 | IV offset = dec.flags & F_UTF8 |
… | |
… | |
962 | SAVEVPTR (PL_curcop); |
1007 | SAVEVPTR (PL_curcop); |
963 | PL_curcop = &cop; |
1008 | PL_curcop = &cop; |
964 | pv_uni_display (uni, dec.cur, dec.end - dec.cur, 20, UNI_DISPLAY_QQ); |
1009 | pv_uni_display (uni, dec.cur, dec.end - dec.cur, 20, UNI_DISPLAY_QQ); |
965 | LEAVE; |
1010 | LEAVE; |
966 | |
1011 | |
967 | croak ("%s, at character offset %d (%s)", |
1012 | croak ("%s, at character offset %d [\"%s\"]", |
968 | dec.err, |
1013 | dec.err, |
969 | (int)offset, |
1014 | (int)offset, |
970 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
1015 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
971 | } |
1016 | } |
972 | |
1017 | |
… | |
… | |
986 | BOOT: |
1031 | BOOT: |
987 | { |
1032 | { |
988 | int i; |
1033 | int i; |
989 | |
1034 | |
990 | memset (decode_hexdigit, 0xff, 256); |
1035 | memset (decode_hexdigit, 0xff, 256); |
|
|
1036 | |
991 | for (i = 10; i--; ) |
1037 | for (i = 0; i < 256; ++i) |
992 | decode_hexdigit ['0' + i] = i; |
1038 | decode_hexdigit [i] = |
993 | |
1039 | i >= '0' && i <= '9' ? i - '0' |
994 | for (i = 7; i--; ) |
1040 | : i >= 'a' && i <= 'f' ? i - 'a' + 10 |
995 | { |
1041 | : i >= 'A' && i <= 'F' ? i - 'A' + 10 |
996 | decode_hexdigit ['a' + i] = 10 + i; |
1042 | : -1; |
997 | decode_hexdigit ['A' + i] = 10 + i; |
|
|
998 | } |
|
|
999 | |
1043 | |
1000 | json_stash = gv_stashpv ("JSON::XS", 1); |
1044 | json_stash = gv_stashpv ("JSON::XS", 1); |
1001 | } |
1045 | } |
1002 | |
1046 | |
1003 | PROTOTYPES: DISABLE |
1047 | PROTOTYPES: DISABLE |
… | |
… | |
1030 | RETVAL = newSVsv (self); |
1074 | RETVAL = newSVsv (self); |
1031 | } |
1075 | } |
1032 | OUTPUT: |
1076 | OUTPUT: |
1033 | RETVAL |
1077 | RETVAL |
1034 | |
1078 | |
|
|
1079 | SV *max_depth (SV *self, int max_depth = 0x80000000UL) |
|
|
1080 | CODE: |
|
|
1081 | { |
|
|
1082 | UV *uv = SvJSON (self); |
|
|
1083 | UV log2 = 0; |
|
|
1084 | |
|
|
1085 | if (max_depth > 0x80000000UL) max_depth = 0x80000000UL; |
|
|
1086 | |
|
|
1087 | while ((1UL << log2) < max_depth) |
|
|
1088 | ++log2; |
|
|
1089 | |
|
|
1090 | *uv = *uv & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); |
|
|
1091 | |
|
|
1092 | RETVAL = newSVsv (self); |
|
|
1093 | } |
|
|
1094 | OUTPUT: |
|
|
1095 | RETVAL |
|
|
1096 | |
1035 | void encode (SV *self, SV *scalar) |
1097 | void encode (SV *self, SV *scalar) |
1036 | PPCODE: |
1098 | PPCODE: |
1037 | XPUSHs (encode_json (scalar, *SvJSON (self))); |
1099 | XPUSHs (encode_json (scalar, *SvJSON (self))); |
1038 | |
1100 | |
1039 | void decode (SV *self, SV *jsonstr) |
1101 | void decode (SV *self, SV *jsonstr) |
… | |
… | |
1044 | |
1106 | |
1045 | void to_json (SV *scalar) |
1107 | void to_json (SV *scalar) |
1046 | ALIAS: |
1108 | ALIAS: |
1047 | objToJson = 0 |
1109 | objToJson = 0 |
1048 | PPCODE: |
1110 | PPCODE: |
1049 | XPUSHs (encode_json (scalar, F_UTF8)); |
1111 | XPUSHs (encode_json (scalar, F_DEFAULT | F_UTF8)); |
1050 | |
1112 | |
1051 | void from_json (SV *jsonstr) |
1113 | void from_json (SV *jsonstr) |
1052 | ALIAS: |
1114 | ALIAS: |
1053 | jsonToObj = 0 |
1115 | jsonToObj = 0 |
1054 | PPCODE: |
1116 | PPCODE: |
1055 | XPUSHs (decode_json (jsonstr, F_UTF8)); |
1117 | XPUSHs (decode_json (jsonstr, F_DEFAULT | F_UTF8)); |
1056 | |
1118 | |