├── .travis.yml ├── COPYING ├── COPYING.LIB ├── README.md ├── base.lisp ├── input-stream.lisp ├── json-streams-tests.asd ├── json-streams.asd ├── output-stream.lisp ├── output.lisp ├── package.lisp ├── parse.lisp ├── stringify.lisp ├── tests ├── JSONTestSuite │ ├── LICENSE │ ├── README.md │ ├── test_parsing │ │ ├── i_number_double_huge_neg_exp.json │ │ ├── i_number_huge_exp.json │ │ ├── i_number_neg_int_huge_exp.json │ │ ├── i_number_pos_double_huge_exp.json │ │ ├── i_number_real_neg_overflow.json │ │ ├── i_number_real_pos_overflow.json │ │ ├── i_number_real_underflow.json │ │ ├── i_number_too_big_neg_int.json │ │ ├── i_number_too_big_pos_int.json │ │ ├── i_number_very_big_negative_int.json │ │ ├── i_object_key_lone_2nd_surrogate.json │ │ ├── i_string_1st_surrogate_but_2nd_missing.json │ │ ├── i_string_1st_valid_surrogate_2nd_invalid.json │ │ ├── i_string_UTF-16LE_with_BOM.json │ │ ├── i_string_UTF-8_invalid_sequence.json │ │ ├── i_string_UTF8_surrogate_U+D800.json │ │ ├── i_string_incomplete_surrogate_and_escape_valid.json │ │ ├── i_string_incomplete_surrogate_pair.json │ │ ├── i_string_incomplete_surrogates_escape_valid.json │ │ ├── i_string_invalid_lonely_surrogate.json │ │ ├── i_string_invalid_surrogate.json │ │ ├── i_string_invalid_utf-8.json │ │ ├── i_string_inverted_surrogates_U+1D11E.json │ │ ├── i_string_iso_latin_1.json │ │ ├── i_string_lone_second_surrogate.json │ │ ├── i_string_lone_utf8_continuation_byte.json │ │ ├── i_string_not_in_unicode_range.json │ │ ├── i_string_overlong_sequence_2_bytes.json │ │ ├── i_string_overlong_sequence_6_bytes.json │ │ ├── i_string_overlong_sequence_6_bytes_null.json │ │ ├── i_string_truncated-utf-8.json │ │ ├── i_string_utf16BE_no_BOM.json │ │ ├── i_string_utf16LE_no_BOM.json │ │ ├── i_structure_500_nested_arrays.json │ │ ├── i_structure_UTF-8_BOM_empty_object.json │ │ ├── n_array_1_true_without_comma.json │ │ ├── n_array_a_invalid_utf8.json │ │ ├── n_array_colon_instead_of_comma.json │ │ ├── n_array_comma_after_close.json │ │ ├── n_array_comma_and_number.json │ │ ├── n_array_double_comma.json │ │ ├── n_array_double_extra_comma.json │ │ ├── n_array_extra_close.json │ │ ├── n_array_extra_comma.json │ │ ├── n_array_incomplete.json │ │ ├── n_array_incomplete_invalid_value.json │ │ ├── n_array_inner_array_no_comma.json │ │ ├── n_array_invalid_utf8.json │ │ ├── n_array_items_separated_by_semicolon.json │ │ ├── n_array_just_comma.json │ │ ├── n_array_just_minus.json │ │ ├── n_array_missing_value.json │ │ ├── n_array_newlines_unclosed.json │ │ ├── n_array_number_and_comma.json │ │ ├── n_array_number_and_several_commas.json │ │ ├── n_array_spaces_vertical_tab_formfeed.json │ │ ├── n_array_star_inside.json │ │ ├── n_array_unclosed.json │ │ ├── n_array_unclosed_trailing_comma.json │ │ ├── n_array_unclosed_with_new_lines.json │ │ ├── n_array_unclosed_with_object_inside.json │ │ ├── n_incomplete_false.json │ │ ├── n_incomplete_null.json │ │ ├── n_incomplete_true.json │ │ ├── n_multidigit_number_then_00.json │ │ ├── n_number_++.json │ │ ├── n_number_+1.json │ │ ├── n_number_+Inf.json │ │ ├── n_number_-01.json │ │ ├── n_number_-1.0..json │ │ ├── n_number_-2..json │ │ ├── n_number_-NaN.json │ │ ├── n_number_.-1.json │ │ ├── n_number_.2e-3.json │ │ ├── n_number_0.1.2.json │ │ ├── n_number_0.3e+.json │ │ ├── n_number_0.3e.json │ │ ├── n_number_0.e1.json │ │ ├── n_number_0_capital_E+.json │ │ ├── n_number_0_capital_E.json │ │ ├── n_number_0e+.json │ │ ├── n_number_0e.json │ │ ├── n_number_1.0e+.json │ │ ├── n_number_1.0e-.json │ │ ├── n_number_1.0e.json │ │ ├── n_number_1_000.json │ │ ├── n_number_1eE2.json │ │ ├── n_number_2.e+3.json │ │ ├── n_number_2.e-3.json │ │ ├── n_number_2.e3.json │ │ ├── n_number_9.e+.json │ │ ├── n_number_Inf.json │ │ ├── n_number_NaN.json │ │ ├── n_number_U+FF11_fullwidth_digit_one.json │ │ ├── n_number_expression.json │ │ ├── n_number_hex_1_digit.json │ │ ├── n_number_hex_2_digits.json │ │ ├── n_number_infinity.json │ │ ├── n_number_invalid+-.json │ │ ├── n_number_invalid-negative-real.json │ │ ├── n_number_invalid-utf-8-in-bigger-int.json │ │ ├── n_number_invalid-utf-8-in-exponent.json │ │ ├── n_number_invalid-utf-8-in-int.json │ │ ├── n_number_minus_infinity.json │ │ ├── n_number_minus_sign_with_trailing_garbage.json │ │ ├── n_number_minus_space_1.json │ │ ├── n_number_neg_int_starting_with_zero.json │ │ ├── n_number_neg_real_without_int_part.json │ │ ├── n_number_neg_with_garbage_at_end.json │ │ ├── n_number_real_garbage_after_e.json │ │ ├── n_number_real_with_invalid_utf8_after_e.json │ │ ├── n_number_real_without_fractional_part.json │ │ ├── n_number_starting_with_dot.json │ │ ├── n_number_with_alpha.json │ │ ├── n_number_with_alpha_char.json │ │ ├── n_number_with_leading_zero.json │ │ ├── n_object_bad_value.json │ │ ├── n_object_bracket_key.json │ │ ├── n_object_comma_instead_of_colon.json │ │ ├── n_object_double_colon.json │ │ ├── n_object_emoji.json │ │ ├── n_object_garbage_at_end.json │ │ ├── n_object_key_with_single_quotes.json │ │ ├── n_object_missing_colon.json │ │ ├── n_object_missing_key.json │ │ ├── n_object_missing_semicolon.json │ │ ├── n_object_missing_value.json │ │ ├── n_object_no-colon.json │ │ ├── n_object_non_string_key.json │ │ ├── n_object_non_string_key_but_huge_number_instead.json │ │ ├── n_object_pi_in_key_and_trailing_comma.json │ │ ├── n_object_repeated_null_null.json │ │ ├── n_object_several_trailing_commas.json │ │ ├── n_object_single_quote.json │ │ ├── n_object_trailing_comma.json │ │ ├── n_object_trailing_comment.json │ │ ├── n_object_trailing_comment_open.json │ │ ├── n_object_trailing_comment_slash_open.json │ │ ├── n_object_trailing_comment_slash_open_incomplete.json │ │ ├── n_object_two_commas_in_a_row.json │ │ ├── n_object_unquoted_key.json │ │ ├── n_object_unterminated-value.json │ │ ├── n_object_with_single_string.json │ │ ├── n_object_with_trailing_garbage.json │ │ ├── n_single_space.json │ │ ├── n_string_1_surrogate_then_escape.json │ │ ├── n_string_1_surrogate_then_escape_u.json │ │ ├── n_string_1_surrogate_then_escape_u1.json │ │ ├── n_string_1_surrogate_then_escape_u1x.json │ │ ├── n_string_accentuated_char_no_quotes.json │ │ ├── n_string_backslash_00.json │ │ ├── n_string_escape_x.json │ │ ├── n_string_escaped_backslash_bad.json │ │ ├── n_string_escaped_ctrl_char_tab.json │ │ ├── n_string_escaped_emoji.json │ │ ├── n_string_incomplete_escape.json │ │ ├── n_string_incomplete_escaped_character.json │ │ ├── n_string_incomplete_surrogate.json │ │ ├── n_string_incomplete_surrogate_escape_invalid.json │ │ ├── n_string_invalid-utf-8-in-escape.json │ │ ├── n_string_invalid_backslash_esc.json │ │ ├── n_string_invalid_unicode_escape.json │ │ ├── n_string_invalid_utf8_after_escape.json │ │ ├── n_string_leading_uescaped_thinspace.json │ │ ├── n_string_no_quotes_with_bad_escape.json │ │ ├── n_string_single_doublequote.json │ │ ├── n_string_single_quote.json │ │ ├── n_string_single_string_no_double_quotes.json │ │ ├── n_string_start_escape_unclosed.json │ │ ├── n_string_unescaped_crtl_char.json │ │ ├── n_string_unescaped_newline.json │ │ ├── n_string_unescaped_tab.json │ │ ├── n_string_unicode_CapitalU.json │ │ ├── n_string_with_trailing_garbage.json │ │ ├── n_structure_100000_opening_arrays.json │ │ ├── n_structure_U+2060_word_joined.json │ │ ├── n_structure_UTF8_BOM_no_data.json │ │ ├── n_structure_angle_bracket_..json │ │ ├── n_structure_angle_bracket_null.json │ │ ├── n_structure_array_trailing_garbage.json │ │ ├── n_structure_array_with_extra_array_close.json │ │ ├── n_structure_array_with_unclosed_string.json │ │ ├── n_structure_ascii-unicode-identifier.json │ │ ├── n_structure_capitalized_True.json │ │ ├── n_structure_close_unopened_array.json │ │ ├── n_structure_comma_instead_of_closing_brace.json │ │ ├── n_structure_double_array.json │ │ ├── n_structure_end_array.json │ │ ├── n_structure_incomplete_UTF8_BOM.json │ │ ├── n_structure_lone-invalid-utf-8.json │ │ ├── n_structure_lone-open-bracket.json │ │ ├── n_structure_no_data.json │ │ ├── n_structure_null-byte-outside-string.json │ │ ├── n_structure_number_with_trailing_garbage.json │ │ ├── n_structure_object_followed_by_closing_object.json │ │ ├── n_structure_object_unclosed_no_value.json │ │ ├── n_structure_object_with_comment.json │ │ ├── n_structure_object_with_trailing_garbage.json │ │ ├── n_structure_open_array_apostrophe.json │ │ ├── n_structure_open_array_comma.json │ │ ├── n_structure_open_array_object.json │ │ ├── n_structure_open_array_open_object.json │ │ ├── n_structure_open_array_open_string.json │ │ ├── n_structure_open_array_string.json │ │ ├── n_structure_open_object.json │ │ ├── n_structure_open_object_close_array.json │ │ ├── n_structure_open_object_comma.json │ │ ├── n_structure_open_object_open_array.json │ │ ├── n_structure_open_object_open_string.json │ │ ├── n_structure_open_object_string_with_apostrophes.json │ │ ├── n_structure_open_open.json │ │ ├── n_structure_single_eacute.json │ │ ├── n_structure_single_star.json │ │ ├── n_structure_trailing_#.json │ │ ├── n_structure_uescaped_LF_before_string.json │ │ ├── n_structure_unclosed_array.json │ │ ├── n_structure_unclosed_array_partial_null.json │ │ ├── n_structure_unclosed_array_unfinished_false.json │ │ ├── n_structure_unclosed_array_unfinished_true.json │ │ ├── n_structure_unclosed_object.json │ │ ├── n_structure_unicode-identifier.json │ │ ├── n_structure_whitespace_U+2060_word_joiner.json │ │ ├── n_structure_whitespace_formfeed.json │ │ ├── y_array_arraysWithSpaces.json │ │ ├── y_array_empty-string.json │ │ ├── y_array_empty.json │ │ ├── y_array_ending_with_newline.json │ │ ├── y_array_false.json │ │ ├── y_array_heterogeneous.json │ │ ├── y_array_null.json │ │ ├── y_array_with_1_and_newline.json │ │ ├── y_array_with_leading_space.json │ │ ├── y_array_with_several_null.json │ │ ├── y_array_with_trailing_space.json │ │ ├── y_number.json │ │ ├── y_number_0e+1.json │ │ ├── y_number_0e1.json │ │ ├── y_number_after_space.json │ │ ├── y_number_double_close_to_zero.json │ │ ├── y_number_int_with_exp.json │ │ ├── y_number_minus_zero.json │ │ ├── y_number_negative_int.json │ │ ├── y_number_negative_one.json │ │ ├── y_number_negative_zero.json │ │ ├── y_number_real_capital_e.json │ │ ├── y_number_real_capital_e_neg_exp.json │ │ ├── y_number_real_capital_e_pos_exp.json │ │ ├── y_number_real_exponent.json │ │ ├── y_number_real_fraction_exponent.json │ │ ├── y_number_real_neg_exp.json │ │ ├── y_number_real_pos_exponent.json │ │ ├── y_number_simple_int.json │ │ ├── y_number_simple_real.json │ │ ├── y_object.json │ │ ├── y_object_basic.json │ │ ├── y_object_duplicated_key.json │ │ ├── y_object_duplicated_key_and_value.json │ │ ├── y_object_empty.json │ │ ├── y_object_empty_key.json │ │ ├── y_object_escaped_null_in_key.json │ │ ├── y_object_extreme_numbers.json │ │ ├── y_object_long_strings.json │ │ ├── y_object_simple.json │ │ ├── y_object_string_unicode.json │ │ ├── y_object_with_newlines.json │ │ ├── y_string_1_2_3_bytes_UTF-8_sequences.json │ │ ├── y_string_accepted_surrogate_pair.json │ │ ├── y_string_accepted_surrogate_pairs.json │ │ ├── y_string_allowed_escapes.json │ │ ├── y_string_backslash_and_u_escaped_zero.json │ │ ├── y_string_backslash_doublequotes.json │ │ ├── y_string_comments.json │ │ ├── y_string_double_escape_a.json │ │ ├── y_string_double_escape_n.json │ │ ├── y_string_escaped_control_character.json │ │ ├── y_string_escaped_noncharacter.json │ │ ├── y_string_in_array.json │ │ ├── y_string_in_array_with_leading_space.json │ │ ├── y_string_last_surrogates_1_and_2.json │ │ ├── y_string_nbsp_uescaped.json │ │ ├── y_string_nonCharacterInUTF-8_U+10FFFF.json │ │ ├── y_string_nonCharacterInUTF-8_U+1FFFF.json │ │ ├── y_string_nonCharacterInUTF-8_U+FFFF.json │ │ ├── y_string_null_escape.json │ │ ├── y_string_one-byte-utf-8.json │ │ ├── y_string_pi.json │ │ ├── y_string_simple_ascii.json │ │ ├── y_string_space.json │ │ ├── y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json │ │ ├── y_string_three-byte-utf-8.json │ │ ├── y_string_two-byte-utf-8.json │ │ ├── y_string_u+2028_line_sep.json │ │ ├── y_string_u+2029_par_sep.json │ │ ├── y_string_uEscape.json │ │ ├── y_string_uescaped_newline.json │ │ ├── y_string_unescaped_char_delete.json │ │ ├── y_string_unicode.json │ │ ├── y_string_unicodeEscapedBackslash.json │ │ ├── y_string_unicode_2.json │ │ ├── y_string_unicode_U+10FFFE_nonchar.json │ │ ├── y_string_unicode_U+1FFFE_nonchar.json │ │ ├── y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json │ │ ├── y_string_unicode_U+2064_invisible_plus.json │ │ ├── y_string_unicode_U+FDD0_nonchar.json │ │ ├── y_string_unicode_U+FFFE_nonchar.json │ │ ├── y_string_unicode_escaped_double_quote.json │ │ ├── y_string_utf8.json │ │ ├── y_string_with_del_character.json │ │ ├── y_structure_lonely_false.json │ │ ├── y_structure_lonely_int.json │ │ ├── y_structure_lonely_negative_real.json │ │ ├── y_structure_lonely_null.json │ │ ├── y_structure_lonely_string.json │ │ ├── y_structure_lonely_true.json │ │ ├── y_structure_string_empty.json │ │ ├── y_structure_trailing_newline.json │ │ ├── y_structure_true_in_array.json │ │ └── y_structure_whitespace_array.json │ └── test_transform │ │ ├── number_1.0.json │ │ ├── number_1.000000000000000005.json │ │ ├── number_1000000000000000.json │ │ ├── number_10000000000000000999.json │ │ ├── number_1e-999.json │ │ ├── number_1e6.json │ │ ├── object_key_nfc_nfd.json │ │ ├── object_key_nfd_nfc.json │ │ ├── object_same_key_different_values.json │ │ ├── object_same_key_same_value.json │ │ ├── object_same_key_unclear_values.json │ │ ├── string_1_escaped_invalid_codepoint.json │ │ ├── string_1_invalid_codepoint.json │ │ ├── string_2_escaped_invalid_codepoints.json │ │ ├── string_2_invalid_codepoints.json │ │ ├── string_3_escaped_invalid_codepoints.json │ │ ├── string_3_invalid_codepoints.json │ │ └── string_with_escaped_NULL.json ├── input.lisp ├── json-streams │ ├── empty.json │ ├── empty.lisp │ ├── invalid-utf-16.json │ ├── invalid-utf-16.lisp │ ├── large-number.json │ ├── large-number.lisp │ ├── multi.json │ ├── multi.lisp │ ├── too-large-number.json │ ├── too-large-number.lisp │ ├── too-small-number.json │ ├── too-small-number.lisp │ ├── utf-16.json │ └── utf-16.lisp ├── json.org │ ├── fail1.json │ ├── fail1.lisp │ ├── fail10.json │ ├── fail10.lisp │ ├── fail11.json │ ├── fail11.lisp │ ├── fail12.json │ ├── fail12.lisp │ ├── fail13.json │ ├── fail13.lisp │ ├── fail14.json │ ├── fail14.lisp │ ├── fail15.json │ ├── fail15.lisp │ ├── fail16.json │ ├── fail16.lisp │ ├── fail17.json │ ├── fail17.lisp │ ├── fail18.json │ ├── fail18.lisp │ ├── fail19.json │ ├── fail19.lisp │ ├── fail2.json │ ├── fail2.lisp │ ├── fail20.json │ ├── fail20.lisp │ ├── fail21.json │ ├── fail21.lisp │ ├── fail22.json │ ├── fail22.lisp │ ├── fail23.json │ ├── fail23.lisp │ ├── fail24.json │ ├── fail24.lisp │ ├── fail25.json │ ├── fail25.lisp │ ├── fail26.json │ ├── fail26.lisp │ ├── fail27.json │ ├── fail27.lisp │ ├── fail28.json │ ├── fail28.lisp │ ├── fail29.json │ ├── fail29.lisp │ ├── fail3.json │ ├── fail3.lisp │ ├── fail30.json │ ├── fail30.lisp │ ├── fail31.json │ ├── fail31.lisp │ ├── fail32.json │ ├── fail32.lisp │ ├── fail33.json │ ├── fail33.lisp │ ├── fail4.json │ ├── fail4.lisp │ ├── fail5.json │ ├── fail5.lisp │ ├── fail6.json │ ├── fail6.lisp │ ├── fail7.json │ ├── fail7.lisp │ ├── fail8.json │ ├── fail8.lisp │ ├── fail9.json │ ├── fail9.lisp │ ├── pass1.json │ ├── pass1.lisp │ ├── pass2.json │ ├── pass2.lisp │ ├── pass3.json │ └── pass3.lisp ├── packages.lisp └── sb-cover.lisp └── write-float.lisp /.travis.yml: -------------------------------------------------------------------------------- 1 | language: lisp 2 | 3 | branches: 4 | only: 5 | - master 6 | 7 | env: 8 | matrix: 9 | - LISP=clisp 10 | - LISP=ccl 11 | - LISP=ecl 12 | - LISP=sbcl 13 | 14 | install: 15 | - curl -L https://github.com/luismbo/cl-travis/raw/master/install.sh | sh 16 | 17 | script: 18 | - cl -e "(ql:quickload :json-streams) (ql:quickload :json-streams-tests) (json-streams-tests::run-all-tests)" 19 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /COPYING.LIB: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # json-streams 2 | 3 | json-streams is a Common Lisp library for reading and writing JSON 4 | text. 5 | 6 | Homepage: https://github.com/rotatef/json-streams 7 | 8 | ## Features 9 | 10 | - Designed to used as a building block for more high level libraries. 11 | - No dependencies. 12 | - Easy to use streaming API. 13 | - Validates input and output. 14 | - Unambiguous mapping of datatypes between lisp and JSON. 15 | - Streaming design, can proccess JSON text of unlimted size. 16 | - Proper handling of Unicode. 17 | 18 | ## High level interface 19 | 20 | ### Streaming interface for output 21 | 22 | Example 23 | 24 | ```common-lisp 25 | (with-json-output (nil :key-encoder #'string-downcase :indent t) 26 | (with-json-object 27 | (json-output-member :first-name "John") 28 | (json-output-member :last-name "Smith") 29 | (with-json-member :is-alive (json-output-boolean t)) 30 | (json-output-member :age 25) 31 | (with-json-member :address 32 | (json-output-alist '((:street-address . "21 2nd Street") 33 | (:city . "New York") 34 | (:state . "NY") 35 | (:postal-code . "10021-3100")))) 36 | (with-json-member :phone-numbers 37 | (with-json-array 38 | (json-output-plist '(:type "home" 39 | :number "212 555-1234")) 40 | (json-output-plist '(:type "office" 41 | :number "646 555-4567")) 42 | (json-output-plist '(:type "mobile" 43 | :number "123 456-7890")))) 44 | (json-output-member :children #()) 45 | (with-json-member :spouse (json-output-null)))) 46 | ``` 47 | 48 | ``` 49 | Macro 50 | JSON-STREAMS:WITH-JSON-OUTPUT (&optional target &rest options) &body body 51 | ``` 52 | 53 | The options are explained under `MAKE-JSON-OUTPUT-STREAM`. Target must 54 | be a character stream or NIL. If target is NIL output is written to a 55 | string that is returned, otherwise the values of body is returned. 56 | 57 | The following functions and macros can only be used inside the body of `WITH-JSON-OUTPUT`: 58 | 59 | - `WITH-JSON-ARRAY` - Use any of the other functions/macros in the body to output elements of the array. 60 | - `WITH-JSON-OBJECT` - Use `WITH-JSON-MEMBER` or `JSON-OUTPUT-MEMBER` in the body. 61 | - `WITH-JSON-MEMBER` - The body must contain one call to one output function/macros to output the value. 62 | - `JSON-OUTPUT-MEMBER` - Outputs the member value using `JSON-OUTPUT-VALUE`. 63 | - `JSON-OUTPUT-VALUE` - string, number, sequence or hash-table. 64 | - `JSON-OUTPUT-BOOLEAN` - `NIL` outputs `false`, anything else outputs `true`. 65 | - `JSON-OUTPUT-NULL` - Always outputs `null`. No arguments. 66 | - `JSON-OUTPUT-ALIST` - Outputs an assoc list as a JSON object using `JSON-OUTPUT-MEMBER`. 67 | - `JSON-OUTPUT-PLIST` - Outputs a propretry list as JSON object using `JSON-OUTPUT-MEMBER`. 68 | 69 | ### Parsing and writing using an unambigious s-expression notation 70 | 71 | The high level interface uses the following datatype mapping: 72 | 73 | JSON | Common Lisp 74 | -------|------------ 75 | true | T 76 | false | NIL 77 | null | :NULL 78 | string | string 79 | number | integer, float or ratio 80 | array | (:ARRAY ... ) 81 | object | (:OBJECT (key . value) ... ) 82 | 83 | The options are explained under `MAKE-JSON-INPUT-STREAM` and 84 | `MAKE-JSON-OUTPUT-STREAM`. 85 | 86 | ``` 87 | Function 88 | JSON-STREAMS:JSON-PARSE source &rest options 89 | => json, position 90 | ``` 91 | 92 | Parses a single JSON text from source. The second value is the 93 | position where parsing stopped. 94 | 95 | ``` 96 | Function 97 | JSON-STREAMS:JSON-PARSE-MULTIPLE source &rest options 98 | => jsons 99 | ``` 100 | 101 | Parses zero or more JSON texts from source. Returns a list of JSON 102 | values. 103 | 104 | ``` 105 | Function 106 | JSON-STREAMS:JSON-STRINGIFY value &optional target &rest options 107 | ``` 108 | 109 | Stringifies value into JSON text. If target is not provided or NIL, 110 | returns a string with the JSON text. Otherwise target must be a 111 | character stream. 112 | 113 | ``` 114 | Function 115 | JSON-STREAMS:JSON-STRINGIFY-MULTIPLE values &optional target &rest options 116 | ``` 117 | 118 | Stringifies multiple json values. 119 | 120 | 121 | ## The streaming interface 122 | 123 | See parse.lisp and stringify.lisp for examples of how to use the 124 | streaming interface. 125 | 126 | ``` 127 | Function 128 | JSON-STREAMS:MAKE-JSON-INPUT-STREAM source &key start end close-stream multiple duplicate-key-check use-ratios max-exponent raw-strings 129 | => json-input-stream 130 | ``` 131 | 132 | - **source** - A character stream or a string. When source is a string, 133 | start and end are bounding index designators of string. 134 | - **use-ratios** - Default false. When false, numbers that can not be 135 | represented as integers are returned as double-floats. Then true, 136 | these numbers are returned as ratios. 137 | - **max-exponent** - Default 325. The maximum (positive and negative) 138 | exponent accepted in numbers. Setting to a high number opens up for a 139 | easy to use denial-of-service attack. 140 | - **raw-strings** - Default false. When true, strings are returned as 141 | `(:STRING numbers*)`, where numbers represent Unicode code points. 142 | For Unicode escape sequences in strings (\uXXXX), no UTF-16 143 | validation or decoding is done. 144 | - **key-encoder** - Default `NIL`. A function taking one 145 | argument. This used by the higher lever functions to transform the 146 | keys of objects into strings. 147 | 148 | ``` 149 | Function 150 | JSON-STREAMS:MAKE-JSON-OUTPUT-STREAM stream &key close-stream multiple duplicate-key-check indent escape-non-ascii 151 | => json-input-stream 152 | ``` 153 | 154 | - **stream** - A character stream. 155 | - **indent** - Default false. When true, the JSON text is broken into lines 156 | and indented. 157 | - **escape-non-ascii** - Default false. When true, any character outside the 158 | ASCII character set will be escaped using the \uXXXX syntax. 159 | 160 | ### Common options 161 | 162 | - **close-stream** - Default false. When true, the source stream will be 163 | closed by JSON-CLOSE. 164 | - **multiple** - Default false. When true, only a single JSON text (object or 165 | array) is expected in the stream. When T, zero or more JSON texts 166 | can be read from or written to stream. 167 | - **duplicate-key-check** - Default true. When true, an error will be 168 | signaled when duplicate keys are detected in an object. Setting 169 | this to false avoids the added overhead of checking for duplicate keys. 170 | 171 | ``` 172 | Function 173 | JSON-STREAMS:JSON-READ json-input-stream 174 | => token 175 | ``` 176 | 177 | Parses JSON text from the underlying stream and returns the next 178 | token. 179 | 180 | ``` 181 | Function 182 | JSON-STREAMS:JSON-WRITE token json-output-stream 183 | => token 184 | ``` 185 | 186 | Outputs JSON text to underlying stream based on the given token. 187 | 188 | ``` 189 | Function 190 | JSON-STREAMS:JSON-CLOSE json-stream &key abort 191 | ``` 192 | 193 | Closes the json-stream. Applications should always call `JSON-CLOSE` 194 | when finished with a JSON stream. This ensures that all syntax errors 195 | are detected. The value of abort is forwarded to `CL:CLOSE` of the 196 | underlying stream (if close-stream was true) and JSON syntax checking 197 | is suppressed. 198 | 199 | ``` 200 | Macro 201 | JSON-STREAMS:WITH-OPEN-JSON-STREAM (var json-stream) &body 202 | ``` 203 | 204 | Binds var to json-stream, executes body, and ensures that JSON-CLOSE 205 | is called on json-stream. 206 | 207 | ## Tokens 208 | 209 | The possible tokens for input and output are 210 | 211 | - `:BEGIN-OBJECT` 212 | - `:END-OBJECT` 213 | - `:BEGIN-ARRAY` 214 | - `:END-ARRAY` 215 | - `:NULL` 216 | - `:FALSE` 217 | - `:TRUE` 218 | - A number 219 | - A string or `(:STRING integer*)` 220 | - `:EOF` 221 | 222 | After a `:BEGIN-OBJECT` is returned, `JSON-READ` will alternate between 223 | returning keys and values of the object, until `:END-OBJECT` is returned 224 | instead of a key. Keys are always returned as strings. Values can be 225 | anything, except `:END-OBJECT`, `:END-ARRAY` and `:EOF`. Thus some kind of 226 | recursive or stack based algorithm is neccearry. 227 | 228 | ### Handling of numbers 229 | 230 | While JSON standard doesn't define any limits on the size of numbers, 231 | many progamming languages does. This library assumes the limits of 232 | JavaScript. In JavaScript there is only one number type, a 64-bit 233 | IEEE 754 double precision float. This has the following implications: 234 | 235 | The syntax doesn't matter: 20, 20.0 or 2e1 are all the same number, 236 | the integer 20. 237 | 238 | The integer range is +/- (expt 10 53). Numbers outside this range 239 | can't be represented accurately. This library will refuse to write an 240 | integer outside this range. If you need to output such large numbers, 241 | convert them to double-float or string. 242 | 243 | At input the handling of numbers outside the integer range depends on 244 | syntax. If the number contains a decimal point or an exponent it will 245 | be returned as a double-float. Otherwise an error will be signalled. 246 | The option `:USE-RATIOS` disables this check. 247 | -------------------------------------------------------------------------------- /base.lisp: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2013 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (in-package #:json-streams) 19 | 20 | 21 | (deftype json-object () 22 | '(cons (member :object) t)) 23 | 24 | (deftype json-array () 25 | '(cons (member :array) t)) 26 | 27 | (deftype json-string () 28 | '(or string 29 | (cons (member :string) t))) 30 | 31 | 32 | (when (= char-code-limit #x10000) 33 | (push 'utf-16-strings *features*)) 34 | 35 | 36 | (defconstant +most-positive-json-integer+ 37 | (expt 2 53)) 38 | 39 | 40 | (defconstant +most-negative-json-integer+ 41 | (- (expt 2 53))) 42 | 43 | 44 | (defvar *json-stream*) 45 | 46 | 47 | (defclass json-stream () 48 | ((stream :initarg :stream) 49 | (close-stream :initarg :close-stream) 50 | (state-stack :initform '(:before-json-text)) 51 | (duplicate-key-check :initarg :duplicate-key-check) 52 | (key-check-stack :initform nil))) 53 | 54 | 55 | (defclass json-input-stream (json-stream) 56 | ((multiple :initarg :multiple) 57 | (use-ratios :initarg :use-ratios) 58 | (max-exponent :initarg :max-exponent) 59 | (raw-strings :initarg :raw-strings) 60 | (current-char :initform nil) 61 | (position :initarg :position :reader json-stream-position) 62 | (newlines :initform '()) 63 | (string-mode :initform nil))) 64 | 65 | 66 | (defclass json-output-stream (json-stream) 67 | ((multiple :initarg :multiple) 68 | (escape-non-ascii :initarg :escape-non-ascii) 69 | (indent :initarg :indent) 70 | (level :initform 0) 71 | (key-encoder :initarg :key-encoder :initform nil))) 72 | 73 | 74 | (defgeneric %json-close (json-stream)) 75 | 76 | 77 | (defun json-close (json-stream &key abort) 78 | (with-slots (stream close-stream) 79 | json-stream 80 | (unless abort 81 | (%json-close json-stream)) 82 | (when close-stream 83 | (close stream :abort abort)))) 84 | 85 | 86 | (defmacro with-open-json-stream ((var stream) &body body) 87 | (let ((errorsp (gensym "ERRORSP"))) 88 | `(let ((,var ,stream) 89 | (,errorsp t)) 90 | (unwind-protect 91 | (multiple-value-prog1 ,@body 92 | (setf ,errorsp nil)) 93 | (json-close ,var :abort ,errorsp))))) 94 | 95 | (defun begin-object () 96 | (with-slots (duplicate-key-check key-check-stack) 97 | *json-stream* 98 | (when duplicate-key-check 99 | (push (make-hash-table :test #'equal) key-check-stack)))) 100 | 101 | (defun end-object () 102 | (with-slots (duplicate-key-check key-check-stack) 103 | *json-stream* 104 | (when duplicate-key-check 105 | (pop key-check-stack)))) 106 | 107 | (defun check-key (key) 108 | (with-slots (duplicate-key-check key-check-stack) 109 | *json-stream* 110 | (when duplicate-key-check 111 | (when (gethash key (car key-check-stack)) 112 | (%json-error "Duplicate key ~S in object" key)) 113 | (setf (gethash key (car key-check-stack)) t)))) 114 | 115 | (defmacro state-stack () 116 | `(slot-value *json-stream* 'state-stack)) 117 | 118 | (defun push-state (new-state) 119 | (push new-state (state-stack))) 120 | 121 | (defun pop-state () 122 | (pop (state-stack))) 123 | 124 | (defun switch-state (new-state) 125 | (pop-state) 126 | (push-state new-state)) 127 | 128 | (define-condition json-error (error) 129 | ((stream :initform *json-stream* :initarg :stream :reader json-error-stream) 130 | (message :initarg :message :reader json-error-message)) 131 | (:report (lambda (c stream) 132 | (format stream "JSON parse error from ~A: ~A" 133 | (json-error-stream c) 134 | (json-error-message c))))) 135 | 136 | 137 | (define-condition json-parse-error (json-error) 138 | () 139 | (:report (lambda (c stream) 140 | (let ((newlines (remove-duplicates (slot-value (json-error-stream c) 'newlines)))) 141 | (format stream "JSON parse error at line ~D column ~D: ~A" 142 | (1+ (length newlines)) 143 | (- (slot-value (json-error-stream c) 'position) 144 | (or (car newlines) 0)) 145 | (json-error-message c)))))) 146 | 147 | (define-condition json-write-error (json-error) 148 | () 149 | (:report (lambda (c stream) 150 | (format stream "JSON write error: ~A." (json-error-message c))))) 151 | 152 | 153 | (defun %json-error (message &rest args) 154 | (switch-state :eof) 155 | (error (etypecase *json-stream* 156 | (json-input-stream 'json-parse-error) 157 | (json-output-stream 'json-write-error)) 158 | :message (apply #'format nil message args))) 159 | 160 | 161 | (defmacro ecase* (keyform &body cases) 162 | (let ((key (gensym "KEY"))) 163 | `(let ((,key ,keyform)) 164 | (case ,key 165 | ,@cases 166 | (otherwise (%json-error "Expected one of ~S, got ~S in state ~S." 167 | ',(mapcar #'car cases) 168 | ,key 169 | (slot-value *json-stream* 'state-stack))))))) 170 | -------------------------------------------------------------------------------- /input-stream.lisp: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2013 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (in-package #:json-streams) 19 | 20 | 21 | (defun make-json-input-stream (source &key 22 | (start 0) 23 | end 24 | close-stream 25 | multiple 26 | use-ratios 27 | (max-exponent 325) 28 | raw-strings 29 | (duplicate-key-check t)) 30 | (make-instance 'json-input-stream 31 | :stream (cond 32 | ((stringp source) 33 | (make-string-input-stream source start end)) 34 | ((and (streamp source) 35 | (input-stream-p source) 36 | (subtypep (stream-element-type source) 37 | 'character)) 38 | source) 39 | (t 40 | (error 'json-error 41 | :stream source 42 | :message (format nil "Source must be a string or a character input stream, got ~S." 43 | (type-of source))))) 44 | :position start 45 | :close-stream close-stream 46 | :duplicate-key-check duplicate-key-check 47 | :multiple multiple 48 | :use-ratios use-ratios 49 | :max-exponent max-exponent 50 | :raw-strings raw-strings)) 51 | 52 | 53 | (defun current-position () 54 | (slot-value *json-stream* 'position)) 55 | 56 | 57 | (defun peek-next-char () 58 | (with-slots (stream) *json-stream* 59 | (peek-char nil stream nil))) 60 | 61 | 62 | (defun read-next-char () 63 | (with-slots (stream current-char position newlines) *json-stream* 64 | (setf current-char (read-char stream nil)) 65 | (when current-char 66 | (incf position) 67 | (when (eql #\Newline current-char) 68 | (push position newlines))) 69 | current-char)) 70 | 71 | 72 | (defun unread-current-char () 73 | (with-slots (stream current-char position) *json-stream* 74 | (when current-char 75 | (decf position) 76 | (unread-char current-char stream)))) 77 | 78 | 79 | (defun skip-space () 80 | (loop while (member (read-next-char) '(#\Space #\Tab #\Newline #\Return))) 81 | (unread-current-char)) 82 | 83 | 84 | (defun expect-string (start string token) 85 | (loop for expect across string 86 | for char = (read-next-char) 87 | unless (eql char expect) 88 | do (%json-error "Expected ~S (as part of ~S), got ~S" expect string char)) 89 | (values token start (current-position))) 90 | 91 | 92 | (defun valid-unescaped-char-p (char) 93 | (when char 94 | (let ((code (char-code char))) 95 | (or (<= #x20 code #x21) 96 | (<= #x23 code #x5b) 97 | (<= #x5d code #x10ffff))))) 98 | 99 | (defun read-string-chars () 100 | (coerce (loop for char = (read-next-char) 101 | while (valid-unescaped-char-p char) 102 | collect char 103 | finally (unread-current-char)) 104 | 'string)) 105 | 106 | 107 | (defun read-4hexdig () 108 | (loop repeat 4 109 | for weight = #x1000 then (/ weight 16) 110 | for char = (read-next-char) 111 | for digit = (and char (digit-char-p char 16)) 112 | do (unless digit 113 | (%json-error "Invalid char ~S in Unicode escape" char)) 114 | sum (* digit weight))) 115 | 116 | 117 | (defun read-escaped (start) 118 | (read-next-char) 119 | (let ((escaped (read-next-char))) 120 | (if (eql #\u escaped) 121 | (values (read-4hexdig) start (current-position)) 122 | (values escaped start (current-position))))) 123 | 124 | 125 | (defun read-integer (&key fractional-p) 126 | (loop for number = 0 then (+ (* number 10) digit) 127 | for size from 0 128 | for char = (read-next-char) 129 | for digit = (and char (digit-char-p char)) 130 | while digit 131 | finally (progn (unread-current-char) 132 | (unless (plusp size) 133 | (%json-error "Expected digit, got ~S" char)) 134 | (return (if fractional-p 135 | (/ number (expt 10 size)) 136 | number))))) 137 | 138 | 139 | (defun read-number (start) 140 | (let* ((sign 1) 141 | (integer-part 0) 142 | (has-dot nil) 143 | (has-e nil) 144 | (fraction-part 0) 145 | (exponent-sign 1) 146 | (exponent 0)) 147 | (when (eql #\- (peek-next-char)) 148 | (read-next-char) 149 | (setf sign -1)) 150 | (if (eql #\0 (peek-next-char)) 151 | (read-next-char) 152 | (setf integer-part (read-integer))) 153 | (when (eql #\. (peek-next-char)) 154 | (setf has-dot t) 155 | (read-next-char) 156 | (setf fraction-part (read-integer :fractional-p t))) 157 | (when (member (peek-next-char) '(#\e #\E)) 158 | (setf has-e t) 159 | (read-next-char) 160 | (case (read-next-char) 161 | (#\+) 162 | (#\- 163 | (setf exponent-sign -1)) 164 | (otherwise 165 | (unread-current-char))) 166 | (setf exponent (read-integer))) 167 | (with-slots (use-ratios max-exponent) *json-stream* 168 | (when (> exponent max-exponent) 169 | (%json-error "Exponent ~A is too large (or small) (max-exponent is ~A)" exponent max-exponent)) 170 | (let ((number (* sign 171 | (+ integer-part fraction-part) 172 | (expt 10 (* exponent-sign exponent))))) 173 | (when (and (not use-ratios) 174 | (not (or has-dot has-e)) 175 | (not (<= +most-negative-json-integer+ number +most-positive-json-integer+))) 176 | (%json-error "Number with integer syntax to large ~D." number)) 177 | (values (if (and (not use-ratios) 178 | (or has-dot has-e) 179 | (or (not (<= +most-negative-json-integer+ number +most-positive-json-integer+)) 180 | (not (integerp number)))) 181 | (handler-case (coerce number 'double-float) 182 | (type-error () (%json-error "Number can't be converted to double-float ~D" 183 | number))) 184 | number) 185 | start 186 | (current-position)))))) 187 | 188 | 189 | (defun read-raw-token (&optional (*json-stream* *json-stream*)) 190 | (with-slots (string-mode) *json-stream* 191 | (let ((start-pos (current-position))) 192 | (cond 193 | ((eql :eof (car (state-stack))) 194 | (values :eof start-pos start-pos)) 195 | (string-mode 196 | (case (peek-next-char) 197 | ((nil) (values :eof start-pos (current-position))) 198 | (#\" (read-next-char) 199 | (setf string-mode nil) 200 | (values :string-delimiter start-pos (current-position))) 201 | (#\\ (read-escaped start-pos)) 202 | (otherwise 203 | (unless (valid-unescaped-char-p (peek-next-char)) 204 | (%json-error "Invalid char in string: ~S " (read-next-char))) 205 | (values (read-string-chars) start-pos (current-position))))) 206 | (t 207 | (skip-space) 208 | (case (peek-next-char) 209 | ((nil) (values :eof start-pos (current-position))) 210 | (#\{ (read-next-char) (values :begin-object start-pos (current-position))) 211 | (#\} (read-next-char) (values :end-object start-pos (current-position))) 212 | (#\[ (read-next-char) (values :begin-array start-pos (current-position))) 213 | (#\] (read-next-char) (values :end-array start-pos (current-position))) 214 | (#\: (read-next-char) (values :name-separator start-pos (current-position))) 215 | (#\, (read-next-char) (values :value-separator start-pos (current-position))) 216 | (#\f (expect-string start-pos "false" :false)) 217 | (#\n (expect-string start-pos "null" :null)) 218 | (#\t (expect-string start-pos "true" :true)) 219 | ((#\- #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9) 220 | (read-number start-pos)) 221 | (#\" (read-next-char) 222 | (setf string-mode t) 223 | (values :string-delimiter start-pos (current-position))) 224 | (otherwise (%json-error "Unexpected character ~S" (read-next-char))))))))) 225 | 226 | 227 | (defun parse-string-to-string (start) 228 | (let (token start2 end) 229 | (values 230 | (with-output-to-string (string) 231 | (loop 232 | (multiple-value-setq (token start2 end) 233 | (read-raw-token)) 234 | (cond 235 | ((eql :string-delimiter token) 236 | (return)) 237 | ((stringp token) 238 | (princ token string)) 239 | ((characterp token) 240 | (case token 241 | ((#\" #\\ #\/) (princ token string)) 242 | (#\b (princ #\Backspace string)) 243 | (#\f (princ #\Page string)) 244 | (#\n (princ #\Newline string)) 245 | (#\r (princ #\Return string)) 246 | (#\t (princ #\Tab string)) 247 | (otherwise (%json-error "Invalid escape \\~A" token)))) 248 | ((integerp token) 249 | (cond 250 | ((<= #xDC00 token #xDFFF) 251 | (%json-error "Invalid unicode escape ~4,'0X" token)) 252 | ((<= #xD800 token #xDBFF) 253 | (let ((lead token) 254 | (tail (read-raw-token))) 255 | (unless (and (integerp tail) (<= #xDC00 tail #xDFFF)) 256 | (%json-error "Invalid UTF-16 surrogate pair ~4,'0X ~4,'0X" lead tail)) 257 | #+JSON-STREAMS::UTF-16-STRINGS (progn (princ (code-char lead) string) 258 | (princ (code-char tail) string)) 259 | #-JSON-STREAMS::UTF-16-STRINGS (princ (code-char (+ #x10000 260 | (ash (- lead #xD800) 10) 261 | (- tail #xDC00))) 262 | string))) 263 | (t 264 | (princ (code-char token) string)))) 265 | (t 266 | (%json-error "Invalid token ~S in string." token))))) 267 | start end))) 268 | 269 | 270 | (defun parse-raw-string (start) 271 | (let (token start2 end raw-string) 272 | (loop 273 | (multiple-value-setq (token start2 end) 274 | (read-raw-token)) 275 | (cond 276 | ((eql :string-delimiter token) 277 | (return)) 278 | ((stringp token) 279 | (loop for char across token 280 | do (push (char-code char) raw-string))) 281 | ((characterp token) 282 | (push (char-code (case token 283 | ((#\" #\\ #\/) token) 284 | (#\b #\Backspace) 285 | (#\f #\Page) 286 | (#\n #\Newline) 287 | (#\r #\Return) 288 | (#\t #\Tab) 289 | (otherwise (%json-error "Invalid escape \\~A" token)))) 290 | raw-string)) 291 | ((integerp token) 292 | (push token raw-string)) 293 | (t 294 | (%json-error "Invalid token ~S in string." token)))) 295 | (values (cons :string (nreverse raw-string)) start end))) 296 | 297 | 298 | (defun parse-string (start) 299 | (if (slot-value *json-stream* 'raw-strings) 300 | (parse-raw-string start) 301 | (parse-string-to-string start))) 302 | 303 | 304 | (defun read-token (&optional start (*json-stream* *json-stream*)) 305 | (with-slots (multiple stream) *json-stream* 306 | (multiple-value-bind (token start2 end) 307 | (read-raw-token) 308 | (unless start 309 | (setf start start2)) 310 | (let ((token-type (etypecase token 311 | (keyword token) 312 | (real :number)))) 313 | (labels ((reprocess () 314 | (ecase (car (state-stack)) 315 | (:before-json-text 316 | (unless multiple 317 | (switch-state :after-json-text)) 318 | (ecase* token-type 319 | (:begin-object 320 | (push-state :begin-object) 321 | (begin-object) 322 | (values token start end)) 323 | (:begin-array 324 | (push-state :before-first-array-item) 325 | (values token start end)) 326 | (:string-delimiter 327 | (parse-string start)) 328 | ((:false :null :true) 329 | (values token start end)) 330 | (:number 331 | (values token start end)) 332 | (:eof 333 | (unless multiple 334 | (%json-error "Empty JSON text")) 335 | (switch-state :eof) 336 | (values :eof start end)))) 337 | 338 | (:begin-object 339 | (ecase* token-type 340 | (:end-object 341 | (pop-state) 342 | (end-object) 343 | (values token start end)) 344 | (:string-delimiter 345 | (switch-state :after-object-key) 346 | (multiple-value-bind (key start end) 347 | (parse-string start) 348 | (check-key key) 349 | (values key start end))))) 350 | 351 | (:after-object-key 352 | (ecase* token-type 353 | (:name-separator 354 | (switch-state :after-object-value) 355 | (push-state :value) 356 | (read-token start)))) 357 | 358 | (:after-object-value 359 | (ecase* token-type 360 | (:value-separator 361 | (switch-state :before-object-key) 362 | (read-token start)) 363 | (:end-object 364 | (pop-state) 365 | (end-object) 366 | (values token start end)))) 367 | 368 | (:before-object-key 369 | (ecase* token-type 370 | (:string-delimiter 371 | (switch-state :after-object-key) 372 | (multiple-value-bind (key start end) 373 | (parse-string start) 374 | (check-key key) 375 | (values key start end))))) 376 | 377 | (:before-first-array-item 378 | (case token-type 379 | (:end-array 380 | (pop-state) 381 | (values token start end)) 382 | (otherwise 383 | (switch-state :after-array-item) 384 | (push-state :value) 385 | (reprocess)))) 386 | 387 | (:after-array-item 388 | (ecase* token-type 389 | (:value-separator 390 | (push-state :value) 391 | (read-token start)) 392 | (:end-array 393 | (pop-state) 394 | (values token start end)))) 395 | 396 | (:value 397 | (pop-state) 398 | (ecase* token-type 399 | (:begin-object 400 | (push-state :begin-object) 401 | (begin-object) 402 | (values token start end)) 403 | (:begin-array 404 | (push-state :before-first-array-item) 405 | (values token start end)) 406 | (:string-delimiter 407 | (parse-string start)) 408 | ((:false :null :true) 409 | (values token start end)) 410 | (:number 411 | (values token start end)))) 412 | 413 | (:after-json-text 414 | (ecase* token-type 415 | (:eof 416 | (switch-state :eof) 417 | (values :eof start end)))) 418 | 419 | (:eof 420 | (values :eof start end))))) 421 | 422 | (reprocess)))))) 423 | 424 | 425 | (defmethod %json-close ((*json-stream* json-input-stream)) 426 | (json-read *json-stream*)) 427 | 428 | 429 | (defun json-read (json-input-stream) 430 | (read-token nil json-input-stream)) 431 | -------------------------------------------------------------------------------- /json-streams-tests.asd: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2013 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (defsystem #:json-streams-tests 19 | :name "json-streams-tests" 20 | :licence "GNU General Public Licence 3.0" 21 | :depends-on (:json-streams :cl-quickcheck :flexi-streams) 22 | :components ((:module "tests" 23 | :serial t 24 | :components 25 | ((:file "packages") 26 | (:file "input"))))) 27 | -------------------------------------------------------------------------------- /json-streams.asd: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2013 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (defsystem #:json-streams 19 | :name "json-streams" 20 | :licence "GNU General Public Licence 3.0" 21 | :author "Thomas Bakketun " 22 | :description "A stream based JSON parser/writer, well suited for higher as building block for higher level libraries." 23 | :depends-on () 24 | :serial t 25 | :components ((:file "package") 26 | (:file "write-float") 27 | (:file "base") 28 | (:file "output-stream") 29 | (:file "input-stream") 30 | (:file "parse") 31 | (:file "output") 32 | (:file "stringify"))) 33 | -------------------------------------------------------------------------------- /output-stream.lisp: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2013 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (in-package #:json-streams) 19 | 20 | 21 | (defun make-json-output-stream (stream &key close-stream multiple indent escape-non-ascii (duplicate-key-check t) key-encoder) 22 | (make-instance 'json-output-stream 23 | :stream stream 24 | :close-stream close-stream 25 | :duplicate-key-check duplicate-key-check 26 | :multiple multiple 27 | :indent indent 28 | :escape-non-ascii escape-non-ascii 29 | :key-encoder key-encoder)) 30 | 31 | 32 | (defun write-indent () 33 | (with-slots (stream indent level) *json-stream* 34 | (when indent 35 | (terpri stream) 36 | (dotimes (i level) 37 | (princ #\Tab stream))))) 38 | 39 | 40 | (defun write-number (number) 41 | (with-slots (stream level) *json-stream* 42 | (unless (or (integerp number) 43 | (floatp number)) 44 | (%json-error "Number must be integer or float, got ~D" number)) 45 | (when (and (integerp number) 46 | (not (<= +most-negative-json-integer+ number +most-positive-json-integer+))) 47 | (%json-error "Integer ~D too large" number)) 48 | (multiple-value-bind (quotient remainder) 49 | (floor number) 50 | (if (zerop remainder) 51 | (princ quotient stream) 52 | (write-float number stream))))) 53 | 54 | 55 | (defun write-unicode (stream code-point) 56 | (flet ((write-escape (value) 57 | (format stream "\\u~4,'0X" value))) 58 | (cond ((<= code-point #xFFFF) 59 | (write-escape code-point)) 60 | (t 61 | (write-escape (+ (ldb (byte 10 10) (- code-point #x10000)) #xD800)) 62 | (write-escape (+ (ldb (byte 10 0) (- code-point #x10000)) #xDC00)))))) 63 | 64 | 65 | (defun write-escaped-string (string) 66 | (with-slots (stream level escape-non-ascii) *json-stream* 67 | (princ #\" stream) 68 | (map nil (lambda (char) 69 | (when (and (integerp char) (< char 128)) 70 | (setf char (code-char char))) 71 | (case char 72 | (#\" (princ "\\\"" stream)) 73 | (#\\ (princ "\\\\" stream)) 74 | (#\Backspace (princ "\\b" stream)) 75 | (#\Page (princ "\\f" stream)) 76 | (#\Newline (princ "\\n" stream)) 77 | (#\Return (princ "\\r" stream)) 78 | (#\Tab (princ "\\t" stream)) 79 | (otherwise 80 | (if (integerp char) 81 | (format stream "\\u~4,'0X" char) 82 | (if (or (char< char #\Space) 83 | (and escape-non-ascii 84 | (> (char-code char) 127))) 85 | (write-unicode stream (char-code char)) 86 | (princ char stream)))))) 87 | (if (stringp string) 88 | string 89 | (cdr string))) 90 | (princ #\" stream))) 91 | 92 | 93 | (defun json-write (token *json-stream*) 94 | (with-slots (state-stack multiple stream indent level) *json-stream* 95 | (let ((token-type (etypecase token 96 | (keyword token) 97 | (null nil) 98 | (real :number) 99 | (json-string :string)))) 100 | (labels 101 | ((write-begin-object () 102 | (begin-object) 103 | (push-state :beginning-of-object) 104 | (princ #\{ stream) 105 | (incf level)) 106 | (write-object-key (first) 107 | (check-key token) 108 | (unless first 109 | (princ #\, stream)) 110 | (write-indent) 111 | (write-escaped-string token) 112 | (princ #\: stream) 113 | (when indent 114 | (princ #\Space stream)) 115 | (switch-state :after-object-key)) 116 | (write-end-object () 117 | (end-object) 118 | (decf level) 119 | (write-indent) 120 | (princ #\} stream) 121 | (pop-state)) 122 | (write-begin-array () 123 | (push-state :beginning-of-array) 124 | (princ #\[ stream) 125 | (incf level)) 126 | (write-array-item (first) 127 | (unless first 128 | (princ #\, stream)) 129 | (write-indent) 130 | (switch-state :after-array-item) 131 | (write-value)) 132 | (write-end-array () 133 | (decf level) 134 | (write-indent) 135 | (princ #\] stream) 136 | (pop-state)) 137 | (write-value () 138 | (push-state :value) 139 | (reprocess)) 140 | (reprocess () 141 | (ecase (car state-stack) 142 | (:before-json-text 143 | (unless multiple 144 | (switch-state :after-json-text)) 145 | (ecase* token-type 146 | (:begin-object (write-begin-object)) 147 | (:begin-array (write-begin-array)) 148 | ((:true :false :null :string :number) (write-value)) 149 | (:eof 150 | (unless multiple 151 | (%json-error "Empty JSON text")) 152 | (switch-state :eof)))) 153 | (:after-json-text 154 | (ecase* token-type 155 | (:eof (switch-state :eof)))) 156 | (:beginning-of-object 157 | (ecase* token-type 158 | (:end-object (write-end-object)) 159 | (:string (write-object-key t)))) 160 | (:after-object-key 161 | (switch-state :after-object-value) 162 | (write-value)) 163 | (:after-object-value 164 | (ecase* token-type 165 | (:end-object (write-end-object)) 166 | (:string (write-object-key nil)))) 167 | (:value 168 | (pop-state) 169 | (ecase* token-type 170 | (:begin-object (write-begin-object)) 171 | (:begin-array (write-begin-array)) 172 | (:false (princ "false" stream)) 173 | (:null (princ "null" stream)) 174 | (:true (princ "true" stream)) 175 | (:string (write-escaped-string token)) 176 | (:number (write-number token)))) 177 | (:beginning-of-array 178 | (case token-type 179 | (:end-array (write-end-array)) 180 | (otherwise (write-array-item t)))) 181 | (:after-array-item 182 | (case token-type 183 | (:end-array (write-end-array)) 184 | (otherwise (write-array-item nil)))) 185 | (:eof 186 | (ecase* token-type 187 | (:eof)))))) 188 | (reprocess)))) 189 | token) 190 | 191 | 192 | (defmethod %json-close ((*json-stream* json-output-stream)) 193 | (json-write :eof *json-stream*)) 194 | 195 | 196 | (defun json-encode-key (key json-stream) 197 | (with-slots (key-encoder) json-stream 198 | (if key-encoder 199 | (funcall key-encoder key) 200 | key))) 201 | -------------------------------------------------------------------------------- /output.lisp: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2017 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (in-package #:json-streams) 19 | 20 | 21 | (defun call-with-json-output (target options function) 22 | (if target 23 | (with-open-json-stream (*json-stream* (apply #'make-json-output-stream target options)) 24 | (funcall function)) 25 | (with-output-to-string (out) 26 | (with-open-json-stream (*json-stream* (apply #'make-json-output-stream out options)) 27 | (funcall function))))) 28 | 29 | 30 | (defmacro with-json-output ((&optional target &rest options) &body body) 31 | `(call-with-json-output ,target (list ,@options) (lambda () ,@body))) 32 | 33 | 34 | (defmacro with-json-array (&body body) 35 | `(progn 36 | (json-write :begin-array *json-stream*) 37 | ,@body 38 | (json-write :end-array *json-stream*))) 39 | 40 | 41 | (defmacro with-json-object (&body body) 42 | `(progn 43 | (json-write :begin-object *json-stream*) 44 | ,@body 45 | (json-write :end-object *json-stream*))) 46 | 47 | 48 | (defmacro with-json-member (key &body body) 49 | `(progn 50 | (json-write (json-encode-key ,key *json-stream*) *json-stream*) 51 | ,@body)) 52 | 53 | 54 | (defun json-output-member (key value) 55 | (json-write (json-encode-key key *json-stream*) *json-stream*) 56 | (json-output-value value)) 57 | 58 | 59 | (defun json-output-value (value) 60 | (etypecase value 61 | ((or string real) 62 | (json-write value *json-stream*)) 63 | (sequence 64 | (with-json-array 65 | (map nil #'json-output-value value))) 66 | (hash-table 67 | (with-json-object 68 | (maphash #'json-output-member value))))) 69 | 70 | 71 | (defun json-output-boolean (value) 72 | (json-write (if value :true :false) *json-stream*)) 73 | 74 | 75 | (defun json-output-null () 76 | (json-write :null *json-stream*)) 77 | 78 | 79 | (defun json-output-alist (alist) 80 | (with-json-object 81 | (loop for (key . value) in alist do 82 | (json-output-member key value)))) 83 | 84 | 85 | (defun json-output-plist (plist) 86 | (with-json-object 87 | (loop for (key value) on plist by #'cddr do 88 | (json-output-member key value)))) 89 | -------------------------------------------------------------------------------- /package.lisp: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2013 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (defpackage #:json-streams 19 | (:use :common-lisp) 20 | (:export 21 | #:json-parse 22 | #:json-parse-multiple 23 | 24 | #:json-stringify 25 | #:json-stringify-multiple 26 | 27 | #:json-stream 28 | #:json-input-stream 29 | #:json-output-stream 30 | 31 | #:json-close 32 | #:with-open-json-stream 33 | 34 | #:json-error 35 | #:json-parse-error 36 | #:json-write-error 37 | 38 | #:make-json-output-stream 39 | #:json-write 40 | 41 | #:make-json-input-stream 42 | #:json-stream-position 43 | #:json-read 44 | 45 | #:json-object 46 | #:json-array 47 | #:json-string 48 | 49 | #:most-positive-json-integer 50 | #:most-negative-json-integer 51 | 52 | #:call-with-json-output 53 | #:with-json-output 54 | #:with-json-array 55 | #:with-json-object 56 | #:with-json-member 57 | #:json-output-member 58 | #:json-output-value 59 | #:json-output-boolean 60 | #:json-output-null 61 | #:json-output-alist 62 | #:json-output-plist)) 63 | -------------------------------------------------------------------------------- /parse.lisp: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2013 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (in-package #:json-streams) 19 | 20 | 21 | (defun json-parse (source &rest options) 22 | (with-open-json-stream (jstream (apply #'make-json-input-stream source options)) 23 | (values (parse-single jstream) 24 | (slot-value jstream 'position)))) 25 | 26 | 27 | (defun json-parse-multiple (source &rest options) 28 | (with-open-json-stream (jstream (apply #'make-json-input-stream source :multiple t options)) 29 | (loop for value = (parse-single jstream) 30 | until (eql :eof value) 31 | collect value))) 32 | 33 | 34 | (defun parse-single (jstream) 35 | (labels ((parse-array (jstream) 36 | (cons :array 37 | (loop for value = (parse-value jstream) 38 | until (eql :end-array value) 39 | collect value))) 40 | (parse-object (jstream) 41 | (cons :object 42 | (loop for key = (parse-value jstream) 43 | until (eql :end-object key) 44 | collect (cons key (parse-value jstream))))) 45 | (parse-value (jstream) 46 | (let ((token (json-read jstream))) 47 | (case token 48 | (:true t) 49 | (:false nil) 50 | (:begin-array (parse-array jstream)) 51 | (:begin-object (parse-object jstream)) 52 | (otherwise token))))) 53 | (values (parse-value jstream) 54 | (json-stream-position jstream)))) 55 | -------------------------------------------------------------------------------- /stringify.lisp: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2013 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (in-package #:json-streams) 19 | 20 | 21 | (defun json-stringify (value &optional target &rest options) 22 | (call-with-json-output target options 23 | (lambda () 24 | (json-stringify-single value)))) 25 | 26 | 27 | (defun json-stringify-multiple (value &optional target &rest options) 28 | (call-with-json-output target (list* :multiple t options) 29 | (lambda () 30 | (map nil #'json-stringify-single value)))) 31 | 32 | 33 | (defun json-stringify-single (value) 34 | (etypecase value 35 | ((or string real) 36 | (json-output-value value)) 37 | ((member t nil) 38 | (json-output-boolean value)) 39 | ((member :null) 40 | (json-output-null)) 41 | (json-array 42 | (with-json-array 43 | (map nil #'json-stringify-single (cdr value)))) 44 | (json-object 45 | (with-json-object 46 | (loop for (key . value) in (cdr value) do 47 | (with-json-member key 48 | (json-stringify-single value))))))) 49 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Nicolas Seriot 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/README.md: -------------------------------------------------------------------------------- 1 | # JSON Parsing Test Suite 2 | A comprehensive test suite for RFC 7159 compliant JSON parsers 3 | 4 | This repository was created as an appendix to the article [Parsing JSON is a Minefield 💣](http://seriot.ch/parsing_json.php). 5 | 6 | **/parsers/** 7 | 8 | This directory contains several parsers and tiny wrappers to turn the parsers into JSON validators, by returning a specific value. 9 | 10 | - `0` the parser did accept the content 11 | - `1` the parser did reject the content 12 | - `>1` the process did crash 13 | - `timeout` happens after 5 seconds 14 | 15 | **/test\_parsing/** 16 | 17 | The name of these files tell if their contents should be accepted or rejected. 18 | 19 | - `y_` content must be accepted by parsers 20 | - `n_` content must be rejected by parsers 21 | - `i_` parsers are free to accept or reject content 22 | 23 | **/test\_transform/** 24 | 25 | These files contain weird structures and characters that parsers may understand differently, eg: 26 | 27 | - huge numbers 28 | - dictionaries with similar keys 29 | - NULL characters 30 | - escaped invalid strings 31 | 32 | These files were used to produce `results/transform.html`. 33 | 34 | **/run_tests.py** 35 | 36 | Run all parsers with all files: 37 | 38 | $ python3 run_tests.py 39 | 40 | Run all parsers with a specific file: 41 | 42 | $ python3 run_tests.py file.json 43 | 44 | Run specific parsers with all files: 45 | 46 | $ echo '["Python 2.7.10", "Python 3.5.2"]' > python_only.json 47 | $ python3 run_tests.py --filter=python_only.json 48 | 49 | The script writes logs in `results/logs.txt`. 50 | 51 | The script then reads `logs.txt` and generates `results/parsing.html`. 52 | 53 | **/results/** 54 | 55 | JSON Parsing Tests 56 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_number_double_huge_neg_exp.json: -------------------------------------------------------------------------------- 1 | [123.456e-789] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_number_huge_exp.json: -------------------------------------------------------------------------------- 1 | [0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_number_neg_int_huge_exp.json: -------------------------------------------------------------------------------- 1 | [-1e+9999] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_number_pos_double_huge_exp.json: -------------------------------------------------------------------------------- 1 | [1.5e+9999] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_number_real_neg_overflow.json: -------------------------------------------------------------------------------- 1 | [-123123e100000] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_number_real_pos_overflow.json: -------------------------------------------------------------------------------- 1 | [123123e100000] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_number_real_underflow.json: -------------------------------------------------------------------------------- 1 | [123e-10000000] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_number_too_big_neg_int.json: -------------------------------------------------------------------------------- 1 | [-123123123123123123123123123123] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_number_too_big_pos_int.json: -------------------------------------------------------------------------------- 1 | [100000000000000000000] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_number_very_big_negative_int.json: -------------------------------------------------------------------------------- 1 | [-237462374673276894279832749832423479823246327846] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_object_key_lone_2nd_surrogate.json: -------------------------------------------------------------------------------- 1 | {"\uDFAA":0} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_1st_surrogate_but_2nd_missing.json: -------------------------------------------------------------------------------- 1 | ["\uDADA"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json: -------------------------------------------------------------------------------- 1 | ["\uD888\u1234"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_UTF-16LE_with_BOM.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_UTF-16LE_with_BOM.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_UTF-8_invalid_sequence.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_UTF-8_invalid_sequence.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_UTF8_surrogate_U+D800.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_UTF8_surrogate_U+D800.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_incomplete_surrogate_and_escape_valid.json: -------------------------------------------------------------------------------- 1 | ["\uD800\n"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_incomplete_surrogate_pair.json: -------------------------------------------------------------------------------- 1 | ["\uDd1ea"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_incomplete_surrogates_escape_valid.json: -------------------------------------------------------------------------------- 1 | ["\uD800\uD800\n"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_invalid_lonely_surrogate.json: -------------------------------------------------------------------------------- 1 | ["\ud800"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_invalid_surrogate.json: -------------------------------------------------------------------------------- 1 | ["\ud800abc"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_invalid_utf-8.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_invalid_utf-8.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_inverted_surrogates_U+1D11E.json: -------------------------------------------------------------------------------- 1 | ["\uDd1e\uD834"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_iso_latin_1.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_iso_latin_1.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_lone_second_surrogate.json: -------------------------------------------------------------------------------- 1 | ["\uDFAA"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_lone_utf8_continuation_byte.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_lone_utf8_continuation_byte.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_not_in_unicode_range.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_not_in_unicode_range.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_overlong_sequence_2_bytes.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_overlong_sequence_2_bytes.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_overlong_sequence_6_bytes.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_overlong_sequence_6_bytes.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_overlong_sequence_6_bytes_null.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_overlong_sequence_6_bytes_null.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_truncated-utf-8.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_truncated-utf-8.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_utf16BE_no_BOM.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_utf16BE_no_BOM.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_string_utf16LE_no_BOM.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/i_string_utf16LE_no_BOM.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_structure_500_nested_arrays.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/i_structure_UTF-8_BOM_empty_object.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_1_true_without_comma.json: -------------------------------------------------------------------------------- 1 | [1 true] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_a_invalid_utf8.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/n_array_a_invalid_utf8.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_colon_instead_of_comma.json: -------------------------------------------------------------------------------- 1 | ["": 1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_comma_after_close.json: -------------------------------------------------------------------------------- 1 | [""], -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_comma_and_number.json: -------------------------------------------------------------------------------- 1 | [,1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_double_comma.json: -------------------------------------------------------------------------------- 1 | [1,,2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_double_extra_comma.json: -------------------------------------------------------------------------------- 1 | ["x",,] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_extra_close.json: -------------------------------------------------------------------------------- 1 | ["x"]] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_extra_comma.json: -------------------------------------------------------------------------------- 1 | ["",] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_incomplete.json: -------------------------------------------------------------------------------- 1 | ["x" -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_incomplete_invalid_value.json: -------------------------------------------------------------------------------- 1 | [x -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_inner_array_no_comma.json: -------------------------------------------------------------------------------- 1 | [3[4]] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_invalid_utf8.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/n_array_invalid_utf8.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_items_separated_by_semicolon.json: -------------------------------------------------------------------------------- 1 | [1:2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_just_comma.json: -------------------------------------------------------------------------------- 1 | [,] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_just_minus.json: -------------------------------------------------------------------------------- 1 | [-] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_missing_value.json: -------------------------------------------------------------------------------- 1 | [ , ""] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_newlines_unclosed.json: -------------------------------------------------------------------------------- 1 | ["a", 2 | 4 3 | ,1, -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_number_and_comma.json: -------------------------------------------------------------------------------- 1 | [1,] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_number_and_several_commas.json: -------------------------------------------------------------------------------- 1 | [1,,] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_spaces_vertical_tab_formfeed.json: -------------------------------------------------------------------------------- 1 | [" a"\f] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_star_inside.json: -------------------------------------------------------------------------------- 1 | [*] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_unclosed.json: -------------------------------------------------------------------------------- 1 | ["" -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_unclosed_trailing_comma.json: -------------------------------------------------------------------------------- 1 | [1, -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_unclosed_with_new_lines.json: -------------------------------------------------------------------------------- 1 | [1, 2 | 1 3 | ,1 -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_array_unclosed_with_object_inside.json: -------------------------------------------------------------------------------- 1 | [{} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_incomplete_false.json: -------------------------------------------------------------------------------- 1 | [fals] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_incomplete_null.json: -------------------------------------------------------------------------------- 1 | [nul] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_incomplete_true.json: -------------------------------------------------------------------------------- 1 | [tru] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_multidigit_number_then_00.json: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_++.json: -------------------------------------------------------------------------------- 1 | [++1234] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_+1.json: -------------------------------------------------------------------------------- 1 | [+1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_+Inf.json: -------------------------------------------------------------------------------- 1 | [+Inf] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_-01.json: -------------------------------------------------------------------------------- 1 | [-01] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_-1.0..json: -------------------------------------------------------------------------------- 1 | [-1.0.] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_-2..json: -------------------------------------------------------------------------------- 1 | [-2.] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_-NaN.json: -------------------------------------------------------------------------------- 1 | [-NaN] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_.-1.json: -------------------------------------------------------------------------------- 1 | [.-1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_.2e-3.json: -------------------------------------------------------------------------------- 1 | [.2e-3] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_0.1.2.json: -------------------------------------------------------------------------------- 1 | [0.1.2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_0.3e+.json: -------------------------------------------------------------------------------- 1 | [0.3e+] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_0.3e.json: -------------------------------------------------------------------------------- 1 | [0.3e] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_0.e1.json: -------------------------------------------------------------------------------- 1 | [0.e1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_0_capital_E+.json: -------------------------------------------------------------------------------- 1 | [0E+] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_0_capital_E.json: -------------------------------------------------------------------------------- 1 | [0E] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_0e+.json: -------------------------------------------------------------------------------- 1 | [0e+] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_0e.json: -------------------------------------------------------------------------------- 1 | [0e] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_1.0e+.json: -------------------------------------------------------------------------------- 1 | [1.0e+] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_1.0e-.json: -------------------------------------------------------------------------------- 1 | [1.0e-] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_1.0e.json: -------------------------------------------------------------------------------- 1 | [1.0e] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_1_000.json: -------------------------------------------------------------------------------- 1 | [1 000.0] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_1eE2.json: -------------------------------------------------------------------------------- 1 | [1eE2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_2.e+3.json: -------------------------------------------------------------------------------- 1 | [2.e+3] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_2.e-3.json: -------------------------------------------------------------------------------- 1 | [2.e-3] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_2.e3.json: -------------------------------------------------------------------------------- 1 | [2.e3] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_9.e+.json: -------------------------------------------------------------------------------- 1 | [9.e+] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_Inf.json: -------------------------------------------------------------------------------- 1 | [Inf] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_NaN.json: -------------------------------------------------------------------------------- 1 | [NaN] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_U+FF11_fullwidth_digit_one.json: -------------------------------------------------------------------------------- 1 | [1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_expression.json: -------------------------------------------------------------------------------- 1 | [1+2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_hex_1_digit.json: -------------------------------------------------------------------------------- 1 | [0x1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_hex_2_digits.json: -------------------------------------------------------------------------------- 1 | [0x42] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_infinity.json: -------------------------------------------------------------------------------- 1 | [Infinity] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_invalid+-.json: -------------------------------------------------------------------------------- 1 | [0e+-1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_invalid-negative-real.json: -------------------------------------------------------------------------------- 1 | [-123.123foo] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_invalid-utf-8-in-bigger-int.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/n_number_invalid-utf-8-in-bigger-int.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_invalid-utf-8-in-exponent.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/n_number_invalid-utf-8-in-exponent.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_invalid-utf-8-in-int.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/n_number_invalid-utf-8-in-int.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_minus_infinity.json: -------------------------------------------------------------------------------- 1 | [-Infinity] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_minus_sign_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | [-foo] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_minus_space_1.json: -------------------------------------------------------------------------------- 1 | [- 1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_neg_int_starting_with_zero.json: -------------------------------------------------------------------------------- 1 | [-012] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_neg_real_without_int_part.json: -------------------------------------------------------------------------------- 1 | [-.123] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_neg_with_garbage_at_end.json: -------------------------------------------------------------------------------- 1 | [-1x] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_real_garbage_after_e.json: -------------------------------------------------------------------------------- 1 | [1ea] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_real_with_invalid_utf8_after_e.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/n_number_real_with_invalid_utf8_after_e.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_real_without_fractional_part.json: -------------------------------------------------------------------------------- 1 | [1.] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_starting_with_dot.json: -------------------------------------------------------------------------------- 1 | [.123] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_with_alpha.json: -------------------------------------------------------------------------------- 1 | [1.2a-3] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_with_alpha_char.json: -------------------------------------------------------------------------------- 1 | [1.8011670033376514H-308] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_number_with_leading_zero.json: -------------------------------------------------------------------------------- 1 | [012] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_bad_value.json: -------------------------------------------------------------------------------- 1 | ["x", truth] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_bracket_key.json: -------------------------------------------------------------------------------- 1 | {[: "x"} 2 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_comma_instead_of_colon.json: -------------------------------------------------------------------------------- 1 | {"x", null} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_double_colon.json: -------------------------------------------------------------------------------- 1 | {"x"::"b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_emoji.json: -------------------------------------------------------------------------------- 1 | {🇨🇭} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_garbage_at_end.json: -------------------------------------------------------------------------------- 1 | {"a":"a" 123} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_key_with_single_quotes.json: -------------------------------------------------------------------------------- 1 | {key: 'value'} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_missing_colon.json: -------------------------------------------------------------------------------- 1 | {"a" b} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_missing_key.json: -------------------------------------------------------------------------------- 1 | {:"b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_missing_semicolon.json: -------------------------------------------------------------------------------- 1 | {"a" "b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_missing_value.json: -------------------------------------------------------------------------------- 1 | {"a": -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_no-colon.json: -------------------------------------------------------------------------------- 1 | {"a" -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_non_string_key.json: -------------------------------------------------------------------------------- 1 | {1:1} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_non_string_key_but_huge_number_instead.json: -------------------------------------------------------------------------------- 1 | {9999E9999:1} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_pi_in_key_and_trailing_comma.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/n_object_pi_in_key_and_trailing_comma.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_repeated_null_null.json: -------------------------------------------------------------------------------- 1 | {null:null,null:null} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_several_trailing_commas.json: -------------------------------------------------------------------------------- 1 | {"id":0,,,,,} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_single_quote.json: -------------------------------------------------------------------------------- 1 | {'a':0} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_trailing_comma.json: -------------------------------------------------------------------------------- 1 | {"id":0,} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_trailing_comment.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}/**/ -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_trailing_comment_open.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}/**// -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_trailing_comment_slash_open.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}// -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_trailing_comment_slash_open_incomplete.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}/ -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_two_commas_in_a_row.json: -------------------------------------------------------------------------------- 1 | {"a":"b",,"c":"d"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_unquoted_key.json: -------------------------------------------------------------------------------- 1 | {a: "b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_unterminated-value.json: -------------------------------------------------------------------------------- 1 | {"a":"a -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_with_single_string.json: -------------------------------------------------------------------------------- 1 | { "foo" : "bar", "a" } -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_object_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}# -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_single_space.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_1_surrogate_then_escape.json: -------------------------------------------------------------------------------- 1 | ["\uD800\"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_1_surrogate_then_escape_u.json: -------------------------------------------------------------------------------- 1 | ["\uD800\u"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_1_surrogate_then_escape_u1.json: -------------------------------------------------------------------------------- 1 | ["\uD800\u1"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_1_surrogate_then_escape_u1x.json: -------------------------------------------------------------------------------- 1 | ["\uD800\u1x"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_accentuated_char_no_quotes.json: -------------------------------------------------------------------------------- 1 | [é] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_backslash_00.json: -------------------------------------------------------------------------------- 1 | ["\"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_escape_x.json: -------------------------------------------------------------------------------- 1 | ["\x00"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_escaped_backslash_bad.json: -------------------------------------------------------------------------------- 1 | ["\\\"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_escaped_ctrl_char_tab.json: -------------------------------------------------------------------------------- 1 | ["\ "] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_escaped_emoji.json: -------------------------------------------------------------------------------- 1 | ["\🌀"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_incomplete_escape.json: -------------------------------------------------------------------------------- 1 | ["\"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_incomplete_escaped_character.json: -------------------------------------------------------------------------------- 1 | ["\u00A"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_incomplete_surrogate.json: -------------------------------------------------------------------------------- 1 | ["\uD834\uDd"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_incomplete_surrogate_escape_invalid.json: -------------------------------------------------------------------------------- 1 | ["\uD800\uD800\x"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_invalid-utf-8-in-escape.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/n_string_invalid-utf-8-in-escape.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_invalid_backslash_esc.json: -------------------------------------------------------------------------------- 1 | ["\a"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_invalid_unicode_escape.json: -------------------------------------------------------------------------------- 1 | ["\uqqqq"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_invalid_utf8_after_escape.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/n_string_invalid_utf8_after_escape.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_leading_uescaped_thinspace.json: -------------------------------------------------------------------------------- 1 | [\u0020"asd"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_no_quotes_with_bad_escape.json: -------------------------------------------------------------------------------- 1 | [\n] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_single_doublequote.json: -------------------------------------------------------------------------------- 1 | " -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_single_quote.json: -------------------------------------------------------------------------------- 1 | ['single quote'] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_single_string_no_double_quotes.json: -------------------------------------------------------------------------------- 1 | abc -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_start_escape_unclosed.json: -------------------------------------------------------------------------------- 1 | ["\ -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_unescaped_crtl_char.json: -------------------------------------------------------------------------------- 1 | ["aa"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_unescaped_newline.json: -------------------------------------------------------------------------------- 1 | ["new 2 | line"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_unescaped_tab.json: -------------------------------------------------------------------------------- 1 | [" "] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_unicode_CapitalU.json: -------------------------------------------------------------------------------- 1 | "\UA66D" -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_string_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | ""x -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_U+2060_word_joined.json: -------------------------------------------------------------------------------- 1 | [⁠] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_UTF8_BOM_no_data.json: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_angle_bracket_..json: -------------------------------------------------------------------------------- 1 | <.> -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_angle_bracket_null.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_array_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | [1]x -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_array_with_extra_array_close.json: -------------------------------------------------------------------------------- 1 | [1]] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_array_with_unclosed_string.json: -------------------------------------------------------------------------------- 1 | ["asd] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_ascii-unicode-identifier.json: -------------------------------------------------------------------------------- 1 | aå -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_capitalized_True.json: -------------------------------------------------------------------------------- 1 | [True] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_close_unopened_array.json: -------------------------------------------------------------------------------- 1 | 1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_comma_instead_of_closing_brace.json: -------------------------------------------------------------------------------- 1 | {"x": true, -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_double_array.json: -------------------------------------------------------------------------------- 1 | [][] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_end_array.json: -------------------------------------------------------------------------------- 1 | ] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_incomplete_UTF8_BOM.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/n_structure_incomplete_UTF8_BOM.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_lone-invalid-utf-8.json: -------------------------------------------------------------------------------- 1 | � -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_lone-open-bracket.json: -------------------------------------------------------------------------------- 1 | [ -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_no_data.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_parsing/n_structure_no_data.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_null-byte-outside-string.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_number_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | 2@ -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_object_followed_by_closing_object.json: -------------------------------------------------------------------------------- 1 | {}} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_object_unclosed_no_value.json: -------------------------------------------------------------------------------- 1 | {"": -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_object_with_comment.json: -------------------------------------------------------------------------------- 1 | {"a":/*comment*/"b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_object_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | {"a": true} "x" -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_array_apostrophe.json: -------------------------------------------------------------------------------- 1 | [' -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_array_comma.json: -------------------------------------------------------------------------------- 1 | [, -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_array_open_object.json: -------------------------------------------------------------------------------- 1 | [{ -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_array_open_string.json: -------------------------------------------------------------------------------- 1 | ["a -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_array_string.json: -------------------------------------------------------------------------------- 1 | ["a" -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_object.json: -------------------------------------------------------------------------------- 1 | { -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_object_close_array.json: -------------------------------------------------------------------------------- 1 | {] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_object_comma.json: -------------------------------------------------------------------------------- 1 | {, -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_object_open_array.json: -------------------------------------------------------------------------------- 1 | {[ -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_object_open_string.json: -------------------------------------------------------------------------------- 1 | {"a -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_object_string_with_apostrophes.json: -------------------------------------------------------------------------------- 1 | {'a' -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_open_open.json: -------------------------------------------------------------------------------- 1 | ["\{["\{["\{["\{ -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_single_eacute.json: -------------------------------------------------------------------------------- 1 | � -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_single_star.json: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_trailing_#.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}#{} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_uescaped_LF_before_string.json: -------------------------------------------------------------------------------- 1 | [\u000A""] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_unclosed_array.json: -------------------------------------------------------------------------------- 1 | [1 -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_unclosed_array_partial_null.json: -------------------------------------------------------------------------------- 1 | [ false, nul -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_unclosed_array_unfinished_false.json: -------------------------------------------------------------------------------- 1 | [ true, fals -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_unclosed_array_unfinished_true.json: -------------------------------------------------------------------------------- 1 | [ false, tru -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_unclosed_object.json: -------------------------------------------------------------------------------- 1 | {"asd":"asd" -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_unicode-identifier.json: -------------------------------------------------------------------------------- 1 | å -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_whitespace_U+2060_word_joiner.json: -------------------------------------------------------------------------------- 1 | [⁠] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/n_structure_whitespace_formfeed.json: -------------------------------------------------------------------------------- 1 | [ ] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_array_arraysWithSpaces.json: -------------------------------------------------------------------------------- 1 | [[] ] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_array_empty-string.json: -------------------------------------------------------------------------------- 1 | [""] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_array_empty.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_array_ending_with_newline.json: -------------------------------------------------------------------------------- 1 | ["a"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_array_false.json: -------------------------------------------------------------------------------- 1 | [false] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_array_heterogeneous.json: -------------------------------------------------------------------------------- 1 | [null, 1, "1", {}] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_array_null.json: -------------------------------------------------------------------------------- 1 | [null] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_array_with_1_and_newline.json: -------------------------------------------------------------------------------- 1 | [1 2 | ] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_array_with_leading_space.json: -------------------------------------------------------------------------------- 1 | [1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_array_with_several_null.json: -------------------------------------------------------------------------------- 1 | [1,null,null,null,2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_array_with_trailing_space.json: -------------------------------------------------------------------------------- 1 | [2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number.json: -------------------------------------------------------------------------------- 1 | [123e65] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_0e+1.json: -------------------------------------------------------------------------------- 1 | [0e+1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_0e1.json: -------------------------------------------------------------------------------- 1 | [0e1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_after_space.json: -------------------------------------------------------------------------------- 1 | [ 4] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_double_close_to_zero.json: -------------------------------------------------------------------------------- 1 | [-0.000000000000000000000000000000000000000000000000000000000000000000000000000001] 2 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_int_with_exp.json: -------------------------------------------------------------------------------- 1 | [20e1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_minus_zero.json: -------------------------------------------------------------------------------- 1 | [-0] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_negative_int.json: -------------------------------------------------------------------------------- 1 | [-123] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_negative_one.json: -------------------------------------------------------------------------------- 1 | [-1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_negative_zero.json: -------------------------------------------------------------------------------- 1 | [-0] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_real_capital_e.json: -------------------------------------------------------------------------------- 1 | [1E22] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_real_capital_e_neg_exp.json: -------------------------------------------------------------------------------- 1 | [1E-2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_real_capital_e_pos_exp.json: -------------------------------------------------------------------------------- 1 | [1E+2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_real_exponent.json: -------------------------------------------------------------------------------- 1 | [123e45] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_real_fraction_exponent.json: -------------------------------------------------------------------------------- 1 | [123.456e78] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_real_neg_exp.json: -------------------------------------------------------------------------------- 1 | [1e-2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_real_pos_exponent.json: -------------------------------------------------------------------------------- 1 | [1e+2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_simple_int.json: -------------------------------------------------------------------------------- 1 | [123] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_number_simple_real.json: -------------------------------------------------------------------------------- 1 | [123.456789] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object.json: -------------------------------------------------------------------------------- 1 | {"asd":"sdf", "dfg":"fgh"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object_basic.json: -------------------------------------------------------------------------------- 1 | {"asd":"sdf"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object_duplicated_key.json: -------------------------------------------------------------------------------- 1 | {"a":"b","a":"c"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object_duplicated_key_and_value.json: -------------------------------------------------------------------------------- 1 | {"a":"b","a":"b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object_empty.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object_empty_key.json: -------------------------------------------------------------------------------- 1 | {"":0} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object_escaped_null_in_key.json: -------------------------------------------------------------------------------- 1 | {"foo\u0000bar": 42} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object_extreme_numbers.json: -------------------------------------------------------------------------------- 1 | { "min": -1.0e+28, "max": 1.0e+28 } -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object_long_strings.json: -------------------------------------------------------------------------------- 1 | {"x":[{"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}], "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object_simple.json: -------------------------------------------------------------------------------- 1 | {"a":[]} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object_string_unicode.json: -------------------------------------------------------------------------------- 1 | {"title":"\u041f\u043e\u043b\u0442\u043e\u0440\u0430 \u0417\u0435\u043c\u043b\u0435\u043a\u043e\u043f\u0430" } -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_object_with_newlines.json: -------------------------------------------------------------------------------- 1 | { 2 | "a": "b" 3 | } -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json: -------------------------------------------------------------------------------- 1 | ["\u0060\u012a\u12AB"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_accepted_surrogate_pair.json: -------------------------------------------------------------------------------- 1 | ["\uD801\udc37"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_accepted_surrogate_pairs.json: -------------------------------------------------------------------------------- 1 | ["\ud83d\ude39\ud83d\udc8d"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_allowed_escapes.json: -------------------------------------------------------------------------------- 1 | ["\"\\\/\b\f\n\r\t"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_backslash_and_u_escaped_zero.json: -------------------------------------------------------------------------------- 1 | ["\\u0000"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_backslash_doublequotes.json: -------------------------------------------------------------------------------- 1 | ["\""] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_comments.json: -------------------------------------------------------------------------------- 1 | ["a/*b*/c/*d//e"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_double_escape_a.json: -------------------------------------------------------------------------------- 1 | ["\\a"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_double_escape_n.json: -------------------------------------------------------------------------------- 1 | ["\\n"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_escaped_control_character.json: -------------------------------------------------------------------------------- 1 | ["\u0012"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_escaped_noncharacter.json: -------------------------------------------------------------------------------- 1 | ["\uFFFF"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_in_array.json: -------------------------------------------------------------------------------- 1 | ["asd"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_in_array_with_leading_space.json: -------------------------------------------------------------------------------- 1 | [ "asd"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_last_surrogates_1_and_2.json: -------------------------------------------------------------------------------- 1 | ["\uDBFF\uDFFF"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_nbsp_uescaped.json: -------------------------------------------------------------------------------- 1 | ["new\u00A0line"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json: -------------------------------------------------------------------------------- 1 | ["􏿿"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json: -------------------------------------------------------------------------------- 1 | ["𛿿"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json: -------------------------------------------------------------------------------- 1 | ["￿"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_null_escape.json: -------------------------------------------------------------------------------- 1 | ["\u0000"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_one-byte-utf-8.json: -------------------------------------------------------------------------------- 1 | ["\u002c"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_pi.json: -------------------------------------------------------------------------------- 1 | ["π"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_simple_ascii.json: -------------------------------------------------------------------------------- 1 | ["asd "] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_space.json: -------------------------------------------------------------------------------- 1 | " " -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json: -------------------------------------------------------------------------------- 1 | ["\uD834\uDd1e"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_three-byte-utf-8.json: -------------------------------------------------------------------------------- 1 | ["\u0821"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_two-byte-utf-8.json: -------------------------------------------------------------------------------- 1 | ["\u0123"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_u+2028_line_sep.json: -------------------------------------------------------------------------------- 1 | ["
"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_u+2029_par_sep.json: -------------------------------------------------------------------------------- 1 | ["
"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_uEscape.json: -------------------------------------------------------------------------------- 1 | ["\u0061\u30af\u30EA\u30b9"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_uescaped_newline.json: -------------------------------------------------------------------------------- 1 | ["new\u000Aline"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_unescaped_char_delete.json: -------------------------------------------------------------------------------- 1 | [""] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_unicode.json: -------------------------------------------------------------------------------- 1 | ["\uA66D"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_unicodeEscapedBackslash.json: -------------------------------------------------------------------------------- 1 | ["\u005C"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_unicode_2.json: -------------------------------------------------------------------------------- 1 | ["⍂㈴⍂"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_unicode_U+10FFFE_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uDBFF\uDFFE"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_unicode_U+1FFFE_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uD83F\uDFFE"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json: -------------------------------------------------------------------------------- 1 | ["\u200B"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json: -------------------------------------------------------------------------------- 1 | ["\u2064"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_unicode_U+FDD0_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uFDD0"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_unicode_U+FFFE_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uFFFE"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_unicode_escaped_double_quote.json: -------------------------------------------------------------------------------- 1 | ["\u0022"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_utf8.json: -------------------------------------------------------------------------------- 1 | ["€𝄞"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_string_with_del_character.json: -------------------------------------------------------------------------------- 1 | ["aa"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_structure_lonely_false.json: -------------------------------------------------------------------------------- 1 | false -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_structure_lonely_int.json: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_structure_lonely_negative_real.json: -------------------------------------------------------------------------------- 1 | -0.1 -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_structure_lonely_null.json: -------------------------------------------------------------------------------- 1 | null -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_structure_lonely_string.json: -------------------------------------------------------------------------------- 1 | "asd" -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_structure_lonely_true.json: -------------------------------------------------------------------------------- 1 | true -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_structure_string_empty.json: -------------------------------------------------------------------------------- 1 | "" -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_structure_trailing_newline.json: -------------------------------------------------------------------------------- 1 | ["a"] 2 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_structure_true_in_array.json: -------------------------------------------------------------------------------- 1 | [true] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_parsing/y_structure_whitespace_array.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/number_1.0.json: -------------------------------------------------------------------------------- 1 | [1.0] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/number_1.000000000000000005.json: -------------------------------------------------------------------------------- 1 | [1.000000000000000005] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/number_1000000000000000.json: -------------------------------------------------------------------------------- 1 | [1000000000000000] 2 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/number_10000000000000000999.json: -------------------------------------------------------------------------------- 1 | [10000000000000000999] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/number_1e-999.json: -------------------------------------------------------------------------------- 1 | [1E-999] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/number_1e6.json: -------------------------------------------------------------------------------- 1 | [1E6] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/object_key_nfc_nfd.json: -------------------------------------------------------------------------------- 1 | {"é":"NFC","é":"NFD"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/object_key_nfd_nfc.json: -------------------------------------------------------------------------------- 1 | {"é":"NFD","é":"NFC"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/object_same_key_different_values.json: -------------------------------------------------------------------------------- 1 | {"a":1,"a":2} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/object_same_key_same_value.json: -------------------------------------------------------------------------------- 1 | {"a":1,"a":1} -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/object_same_key_unclear_values.json: -------------------------------------------------------------------------------- 1 | {"a":0, "a":-0} 2 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/string_1_escaped_invalid_codepoint.json: -------------------------------------------------------------------------------- 1 | ["\uD800"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/string_1_invalid_codepoint.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_transform/string_1_invalid_codepoint.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/string_2_escaped_invalid_codepoints.json: -------------------------------------------------------------------------------- 1 | ["\uD800\uD800"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/string_2_invalid_codepoints.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_transform/string_2_invalid_codepoints.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/string_3_escaped_invalid_codepoints.json: -------------------------------------------------------------------------------- 1 | ["\uD800\uD800\uD800"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/string_3_invalid_codepoints.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/JSONTestSuite/test_transform/string_3_invalid_codepoints.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/test_transform/string_with_escaped_NULL.json: -------------------------------------------------------------------------------- 1 | ["A\u0000B"] -------------------------------------------------------------------------------- /tests/input.lisp: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2013 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (in-package :json-streams-tests) 19 | 20 | 21 | (defun run-all-tests () 22 | (quickcheck 23 | (random-test) 24 | (run-test-files) 25 | (json-test-suite-test-parsing))) 26 | 27 | (define (a-json-array) 28 | (cons :array (generate (a-list a-json-value)))) 29 | 30 | (define (a-json-object) 31 | (cons :object 32 | (remove-duplicates 33 | (loop for (key value) in (generate (a-list (a-tuple #'a-string a-json-value))) 34 | collect (cons key value)) 35 | :key #'car 36 | :test #'string=))) 37 | 38 | (define (a-double-float) 39 | (coerce (generate a-real) 'double-float)) 40 | 41 | (define (a-number) 42 | (generate (a-member an-integer a-double-float))) 43 | 44 | (define (a-json-text) 45 | (pick-weighted 46 | (5 (generate a-json-array)) 47 | (5 (generate a-json-object)) 48 | (1 (generate a-json-value)))) 49 | 50 | (define (a-json-value) 51 | (pick-weighted 52 | (10 :null) 53 | (10 (generate a-boolean)) 54 | (10 (generate a-number)) 55 | (10 (generate #'a-string)) 56 | (1 (generate (a-member a-json-array a-json-object))))) 57 | 58 | (defun random-test () 59 | (for-all ((json a-json-text)) 60 | (is= json (json-parse (princ (json-stringify json)))) 61 | (terpri) (terpri))) 62 | 63 | 64 | (defun run-test-files (&optional (dir (asdf:system-relative-pathname :json-streams "tests/"))) 65 | (dolist (file (directory (merge-pathnames "*/*.json" dir))) 66 | (run-test-file file))) 67 | 68 | 69 | (defun read-all-tokens (in options) 70 | (with-open-json-stream (jstream (apply #'make-json-input-stream in options)) 71 | (loop for token = (handler-case (json-read jstream) 72 | (json-parse-error () :error)) 73 | collect token 74 | until (member token '(:eof :error))))) 75 | 76 | (defmacro with-open-file* ((stream pathname &rest options) &body body) 77 | (let ((binary (gensym "BINARY-STREAM"))) 78 | `(with-open-file (,binary ,pathname :element-type 'flex:octet ,@options) 79 | (with-open-stream (,stream (flex:make-flexi-stream ,binary :external-format '(:utf-8 :eol-style :lf))) 80 | ,@body)))) 81 | 82 | 83 | (defun run-test-file (file) 84 | (with-open-file* (in (make-pathname :type "lisp" :defaults file)) 85 | (loop for options = (read in nil) 86 | for expected-tokens = (read in nil) 87 | while expected-tokens 88 | do 89 | (with-open-file* (in file) 90 | (loop for token-num from 0 91 | for expected in expected-tokens 92 | for got in (read-all-tokens in options) 93 | do (named (format nil "~A ~S ~D" options (pathname-name file) token-num) 94 | (is= expected got))))))) 95 | 96 | 97 | 98 | (defun json-test-suite-test-file (pathname) 99 | (with-open-file* (in pathname) 100 | (let* ((tokens (read-all-tokens in '(:duplicate-key-check nil))) 101 | (errorsp (not (not (find :error tokens))))) 102 | (values (ecase (char (pathname-name pathname) 0) 103 | (#\y (not errorsp)) 104 | (#\n errorsp) 105 | (#\i t)) 106 | errorsp 107 | tokens 108 | (unless errorsp 109 | (with-output-to-string (out) 110 | (with-open-json-stream (json (make-json-output-stream out :duplicate-key-check nil)) 111 | (dolist (token tokens) 112 | (json-write token json))))))))) 113 | 114 | (defparameter *json-test-suite-skip-tests* 115 | '("i_string_iso_latin_1" 116 | "i_string_not_in_unicode_range" 117 | "i_string_overlong_sequence_2_bytes" 118 | "i_string_overlong_sequence_6_bytes" 119 | "i_string_overlong_sequence_6_bytes_null" 120 | "i_string_UTF-16LE_with_BOM" 121 | "i_string_UTF-8_invalid_sequence" 122 | "i_string_UTF8_surrogate_U+D800" 123 | "i_string_invalid_utf-8" 124 | "i_string_lone_utf8_continuation_byte" 125 | "i_string_truncated-utf-8" 126 | "i_string_utf16BE_no_BOM" 127 | "i_string_utf16LE_no_BOM" 128 | "n_array_a_invalid_utf8" 129 | "n_array_invalid_utf8" 130 | "n_number_invalid-utf-8-in-bigger-int" 131 | "n_number_invalid-utf-8-in-exponent" 132 | "n_number_invalid-utf-8-in-int" 133 | "n_number_real_with_invalid_utf8_after_e" 134 | "n_object_pi_in_key_and_trailing_comma" 135 | "n_string_invalid-utf-8-in-escape" 136 | "n_string_invalid_utf8_after_escape" 137 | "n_structure_incomplete_UTF8_BOM" 138 | "n_structure_lone-invalid-utf-8" 139 | "n_structure_single_eacute" 140 | "y_string_nonCharacterInUTF-8_U+FFFF")) 141 | 142 | (defun json-test-suite-test-parsing (&optional (dir (asdf:system-relative-pathname :json-streams "tests/JSONTestSuite/test_parsing/"))) 143 | (loop for file in (directory (merge-pathnames "*.json" dir)) 144 | for name = (pathname-name file) 145 | do (format t "~%~A ... " name) 146 | (finish-output) 147 | (if (find name *json-test-suite-skip-tests* :test #'string=) 148 | (princ "SKIP") 149 | (with-simple-restart (contiune "Test ~A" name) 150 | (multiple-value-bind (ok errorsp) 151 | (json-test-suite-test-file file) 152 | (when errorsp 153 | (princ "(error)")) 154 | (when ok 155 | (princ " PASSED")) 156 | (test ok)))))) 157 | -------------------------------------------------------------------------------- /tests/json-streams/empty.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/json-streams/empty.json -------------------------------------------------------------------------------- /tests/json-streams/empty.lisp: -------------------------------------------------------------------------------- 1 | (:multiple t) 2 | 3 | (:eof) 4 | -------------------------------------------------------------------------------- /tests/json-streams/invalid-utf-16.json: -------------------------------------------------------------------------------- 1 | ["missing trail1: \uD900", 2 | "missing trail2: \uD900B", 3 | "missing trail3: \uD900\u0065", 4 | "missing lead: \uDC10", 5 | "wrong order: \uDD1E\uD834"] 6 | -------------------------------------------------------------------------------- /tests/json-streams/invalid-utf-16.lisp: -------------------------------------------------------------------------------- 1 | () 2 | (:begin-array 3 | :error) 4 | 5 | (:raw-strings t) 6 | (:begin-array 7 | (:string 109 105 115 115 105 110 103 32 116 114 97 105 108 49 58 32 #xD900) 8 | (:string 109 105 115 115 105 110 103 32 116 114 97 105 108 50 58 32 #xD900 66) 9 | (:string 109 105 115 115 105 110 103 32 116 114 97 105 108 51 58 32 #xD900 #x65) 10 | (:string 109 105 115 115 105 110 103 32 108 101 97 100 58 32 #xDC10) 11 | (:string 119 114 111 110 103 32 111 114 100 101 114 58 32 #xDD1E #xD834) 12 | :end-array 13 | :eof) 14 | -------------------------------------------------------------------------------- /tests/json-streams/large-number.json: -------------------------------------------------------------------------------- 1 | [5e300,9007199254740993] 2 | -------------------------------------------------------------------------------- /tests/json-streams/large-number.lisp: -------------------------------------------------------------------------------- 1 | () 2 | (:begin-array 3 | 5d300 4 | :error) 5 | 6 | (:use-ratios t) 7 | (:begin-array 8 | 5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 9 | 9007199254740993 10 | :end-array 11 | :eof) 12 | -------------------------------------------------------------------------------- /tests/json-streams/multi.json: -------------------------------------------------------------------------------- 1 | ["one"]["two"] 2 | 3 | {"three": 3} 4 | -------------------------------------------------------------------------------- /tests/json-streams/multi.lisp: -------------------------------------------------------------------------------- 1 | (:multiple t) 2 | 3 | (:begin-array 4 | "one" 5 | :end-array 6 | :begin-array 7 | "two" 8 | :end-array 9 | :begin-object 10 | "three" 11 | 3 12 | :end-object 13 | :eof) 14 | -------------------------------------------------------------------------------- /tests/json-streams/too-large-number.json: -------------------------------------------------------------------------------- 1 | [5e10000] 2 | -------------------------------------------------------------------------------- /tests/json-streams/too-large-number.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json-streams/too-small-number.json: -------------------------------------------------------------------------------- 1 | [5e-10000] 2 | -------------------------------------------------------------------------------- /tests/json-streams/too-small-number.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json-streams/utf-16.json: -------------------------------------------------------------------------------- 1 | ["\uD834\uDD1Ea\"\b\f\n\r\t"] 2 | -------------------------------------------------------------------------------- /tests/json-streams/utf-16.lisp: -------------------------------------------------------------------------------- 1 | () 2 | (:begin-array 3 | "𝄞a\" 4 | " 5 | :end-array 6 | :eof) 7 | 8 | (:raw-strings t) 9 | (:begin-array 10 | (:string #xD834 #xDD1E 97 34 8 12 10 13 9) 11 | :end-array 12 | :eof) 13 | -------------------------------------------------------------------------------- /tests/json.org/fail1.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotatef/json-streams/5da012e8133affbf75024e7500feb37394690752/tests/json.org/fail1.json -------------------------------------------------------------------------------- /tests/json.org/fail1.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:error) 4 | -------------------------------------------------------------------------------- /tests/json.org/fail10.json: -------------------------------------------------------------------------------- 1 | {"Extra value after close": true} "misplaced quoted value" -------------------------------------------------------------------------------- /tests/json.org/fail10.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | "Extra value after close" :true 5 | :end-object 6 | :error) 7 | -------------------------------------------------------------------------------- /tests/json.org/fail11.json: -------------------------------------------------------------------------------- 1 | {"Illegal expression": 1 + 2} -------------------------------------------------------------------------------- /tests/json.org/fail11.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | "Illegal expression" 1 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/fail12.json: -------------------------------------------------------------------------------- 1 | {"Illegal invocation": alert()} -------------------------------------------------------------------------------- /tests/json.org/fail12.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | "Illegal invocation" 5 | :error 6 | ) 7 | -------------------------------------------------------------------------------- /tests/json.org/fail13.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot have leading zeroes": 013} -------------------------------------------------------------------------------- /tests/json.org/fail13.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | "Numbers cannot have leading zeroes" 0 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/fail14.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot be hex": 0x14} -------------------------------------------------------------------------------- /tests/json.org/fail14.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | "Numbers cannot be hex" 5 | 0 6 | :error) 7 | -------------------------------------------------------------------------------- /tests/json.org/fail15.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \x15"] -------------------------------------------------------------------------------- /tests/json.org/fail15.lisp: -------------------------------------------------------------------------------- 1 | () 2 | (:begin-array 3 | :error) 4 | 5 | (:raw-strings t) 6 | (:begin-array 7 | :error) 8 | -------------------------------------------------------------------------------- /tests/json.org/fail16.json: -------------------------------------------------------------------------------- 1 | [\naked] -------------------------------------------------------------------------------- /tests/json.org/fail16.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail17.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \017"] -------------------------------------------------------------------------------- /tests/json.org/fail17.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail18.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /tests/json.org/fail18.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :begin-array 5 | :begin-array 6 | :begin-array 7 | :begin-array 8 | :begin-array 9 | :begin-array 10 | :begin-array 11 | :begin-array 12 | :begin-array 13 | :begin-array 14 | :begin-array 15 | :begin-array 16 | :begin-array 17 | :begin-array 18 | :begin-array 19 | :begin-array 20 | :begin-array 21 | :begin-array 22 | :begin-array 23 | "Too deep" 24 | :end-array 25 | :end-array 26 | :end-array 27 | :end-array 28 | :end-array 29 | :end-array 30 | :end-array 31 | :end-array 32 | :end-array 33 | :end-array 34 | :end-array 35 | :end-array 36 | :end-array 37 | :end-array 38 | :end-array 39 | :end-array 40 | :end-array 41 | :end-array 42 | :end-array 43 | :end-array 44 | :eof) 45 | -------------------------------------------------------------------------------- /tests/json.org/fail19.json: -------------------------------------------------------------------------------- 1 | {"Missing colon" null} -------------------------------------------------------------------------------- /tests/json.org/fail19.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | "Missing colon" 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/fail2.json: -------------------------------------------------------------------------------- 1 | ["Unclosed array" -------------------------------------------------------------------------------- /tests/json.org/fail2.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array "Unclosed array" :error) 4 | -------------------------------------------------------------------------------- /tests/json.org/fail20.json: -------------------------------------------------------------------------------- 1 | {"Double colon":: null} -------------------------------------------------------------------------------- /tests/json.org/fail20.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | "Double colon" 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/fail21.json: -------------------------------------------------------------------------------- 1 | {"Comma instead of colon", null} 2 | -------------------------------------------------------------------------------- /tests/json.org/fail21.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | "Comma instead of colon" 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/fail22.json: -------------------------------------------------------------------------------- 1 | ["Colon instead of comma": false] -------------------------------------------------------------------------------- /tests/json.org/fail22.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | "Colon instead of comma" 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/fail23.json: -------------------------------------------------------------------------------- 1 | 2 | 3 | ["Bad value", truth] 4 | -------------------------------------------------------------------------------- /tests/json.org/fail23.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | "Bad value" 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/fail24.json: -------------------------------------------------------------------------------- 1 | ['single quote'] -------------------------------------------------------------------------------- /tests/json.org/fail24.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail25.json: -------------------------------------------------------------------------------- 1 | [" tab character in string "] -------------------------------------------------------------------------------- /tests/json.org/fail25.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail26.json: -------------------------------------------------------------------------------- 1 | ["tab\ character\ in\ string\ "] -------------------------------------------------------------------------------- /tests/json.org/fail26.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail27.json: -------------------------------------------------------------------------------- 1 | ["line 2 | break"] -------------------------------------------------------------------------------- /tests/json.org/fail27.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail28.json: -------------------------------------------------------------------------------- 1 | ["line\ 2 | break"] -------------------------------------------------------------------------------- /tests/json.org/fail28.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail29.json: -------------------------------------------------------------------------------- 1 | [0e] -------------------------------------------------------------------------------- /tests/json.org/fail29.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail3.json: -------------------------------------------------------------------------------- 1 | {unquoted_key: "keys must be quoted"} -------------------------------------------------------------------------------- /tests/json.org/fail3.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail30.json: -------------------------------------------------------------------------------- 1 | [0e+] -------------------------------------------------------------------------------- /tests/json.org/fail30.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail31.json: -------------------------------------------------------------------------------- 1 | [0e+-1] -------------------------------------------------------------------------------- /tests/json.org/fail31.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail32.json: -------------------------------------------------------------------------------- 1 | {"Comma instead if closing brace": true, -------------------------------------------------------------------------------- /tests/json.org/fail32.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | "Comma instead if closing brace" :true 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/fail33.json: -------------------------------------------------------------------------------- 1 | ["mismatch"} -------------------------------------------------------------------------------- /tests/json.org/fail33.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | "mismatch" 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/fail4.json: -------------------------------------------------------------------------------- 1 | ["extra comma",] -------------------------------------------------------------------------------- /tests/json.org/fail4.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | "extra comma" 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/fail5.json: -------------------------------------------------------------------------------- 1 | ["double extra comma",,] -------------------------------------------------------------------------------- /tests/json.org/fail5.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | "double extra comma" 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/fail6.json: -------------------------------------------------------------------------------- 1 | [ , "<-- missing value"] -------------------------------------------------------------------------------- /tests/json.org/fail6.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | :error) 5 | -------------------------------------------------------------------------------- /tests/json.org/fail7.json: -------------------------------------------------------------------------------- 1 | ["Comma after the close"], -------------------------------------------------------------------------------- /tests/json.org/fail7.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | "Comma after the close" 5 | :end-array 6 | :error) 7 | -------------------------------------------------------------------------------- /tests/json.org/fail8.json: -------------------------------------------------------------------------------- 1 | ["Extra close"]] -------------------------------------------------------------------------------- /tests/json.org/fail8.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-array 4 | "Extra close" 5 | :end-array 6 | :error) 7 | -------------------------------------------------------------------------------- /tests/json.org/fail9.json: -------------------------------------------------------------------------------- 1 | {"Extra comma": true,} -------------------------------------------------------------------------------- /tests/json.org/fail9.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | "Extra comma" :true 5 | :error) 6 | -------------------------------------------------------------------------------- /tests/json.org/pass1.json: -------------------------------------------------------------------------------- 1 | [ 2 | "JSON Test Pattern pass1", 3 | {"object with 1 member":["array with 1 element"]}, 4 | {}, 5 | [], 6 | -42, 7 | true, 8 | false, 9 | null, 10 | { 11 | "integer": 1234567890, 12 | "real": -9876.543210, 13 | "e": 0.123456789e-12, 14 | "E": 1.234567890E+34, 15 | "": 23456789012E66, 16 | "zero": 0, 17 | "one": 1, 18 | "space": " ", 19 | "quote": "\"", 20 | "backslash": "\\", 21 | "controls": "\b\f\n\r\t", 22 | "slash": "/ & \/", 23 | "alpha": "abcdefghijklmnopqrstuvwyz", 24 | "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", 25 | "digit": "0123456789", 26 | "0123456789": "digit", 27 | "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", 28 | "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", 29 | "true": true, 30 | "false": false, 31 | "null": null, 32 | "array":[ ], 33 | "object":{ }, 34 | "address": "50 St. James Street", 35 | "url": "http://www.JSON.org/", 36 | "comment": "// /* */": " ", 38 | " s p a c e d " :[1,2 , 3 39 | 40 | , 41 | 42 | 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], 43 | "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", 44 | "quotes": "" \u0022 %22 0x22 034 "", 45 | "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" 46 | : "A key can be any string" 47 | }, 48 | 0.5 ,98.6 49 | , 50 | 99.44 51 | , 52 | 53 | 1066, 54 | 1e1, 55 | 0.1e1, 56 | 1e-1, 57 | 1e00,2e+00,2e-00 58 | ,"rosebud"] -------------------------------------------------------------------------------- /tests/json.org/pass1.lisp: -------------------------------------------------------------------------------- 1 | () 2 | (:BEGIN-ARRAY 3 | "JSON Test Pattern pass1" 4 | :BEGIN-OBJECT "object with 1 member" :BEGIN-ARRAY "array with 1 element" :END-ARRAY :END-OBJECT 5 | :BEGIN-OBJECT :END-OBJECT 6 | :BEGIN-ARRAY :END-ARRAY 7 | -42 8 | :TRUE 9 | :FALSE 10 | :NULL 11 | :BEGIN-OBJECT 12 | "integer" 1234567890 13 | "real" -9876.543210d0 14 | "e" 0.123456789d-12 15 | "E" 1.23456789d34 16 | "" 23456789012d66 17 | "zero" 0 18 | "one" 1 19 | "space" " " 20 | "quote" "\"" 21 | "backslash" "\\" 22 | "controls" " 23 | " 24 | "slash" "/ & /" 25 | "alpha" "abcdefghijklmnopqrstuvwyz" 26 | "ALPHA" "ABCDEFGHIJKLMNOPQRSTUVWYZ" 27 | "digit" "0123456789" 28 | "0123456789" "digit" 29 | "special" "`1~!@#$%^&*()_+-={':[,]}|;.?" 30 | "hex" "ģ䕧覫췯ꯍ" 31 | "true" :TRUE 32 | "false" :FALSE 33 | "null" :NULL 34 | "array" :BEGIN-ARRAY :END-ARRAY 35 | "object" :BEGIN-OBJECT :END-OBJECT 36 | "address" "50 St. James Street" 37 | "url" "http://www.JSON.org/" 38 | "comment" "// /* */" " " 40 | " s p a c e d " :BEGIN-ARRAY 1 2 3 41 | 4 5 6 7 :END-ARRAY "compact" 42 | :BEGIN-ARRAY 43 | 1 2 3 4 5 6 7 44 | :END-ARRAY 45 | "jsontext" "{\"object with 1 member\":[\"array with 1 element\"]}" 46 | "quotes" "" \" %22 0x22 034 "" 47 | "/\\\"쫾몾ꮘﳞ볚 48 | `1~!@#$%^&*()_+-=[]{}|;:',./<>?" 49 | "A key can be any string" 50 | :END-OBJECT 51 | 0.5d0 98.6d0 52 | 99.44d0 53 | 1066 54 | 10 55 | 1 56 | 0.1d0 57 | 1 2 2 58 | "rosebud" :END-ARRAY 59 | :eof) 60 | -------------------------------------------------------------------------------- /tests/json.org/pass2.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /tests/json.org/pass2.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | 4 | (:begin-array 5 | :begin-array 6 | :begin-array 7 | :begin-array 8 | :begin-array 9 | :begin-array 10 | :begin-array 11 | :begin-array 12 | :begin-array 13 | :begin-array 14 | :begin-array 15 | :begin-array 16 | :begin-array 17 | :begin-array 18 | :begin-array 19 | :begin-array 20 | :begin-array 21 | :begin-array 22 | :begin-array 23 | "Not too deep" 24 | :end-array 25 | :end-array 26 | :end-array 27 | :end-array 28 | :end-array 29 | :end-array 30 | :end-array 31 | :end-array 32 | :end-array 33 | :end-array 34 | :end-array 35 | :end-array 36 | :end-array 37 | :end-array 38 | :end-array 39 | :end-array 40 | :end-array 41 | :end-array 42 | :end-array 43 | :eof) 44 | -------------------------------------------------------------------------------- /tests/json.org/pass3.json: -------------------------------------------------------------------------------- 1 | { 2 | "JSON Test Pattern pass3": { 3 | "The outermost value": "must be an object or array.", 4 | "In this test": "It is an object." 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/json.org/pass3.lisp: -------------------------------------------------------------------------------- 1 | () 2 | 3 | (:begin-object 4 | "JSON Test Pattern pass3" 5 | :begin-object 6 | "The outermost value" "must be an object or array." 7 | "In this test" "It is an object." 8 | :end-object 9 | :end-object 10 | :eof) 11 | -------------------------------------------------------------------------------- /tests/packages.lisp: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2013 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (defpackage :json-streams-tests 19 | (:use :common-lisp :json-streams :cl-quickcheck)) 20 | -------------------------------------------------------------------------------- /tests/sb-cover.lisp: -------------------------------------------------------------------------------- 1 | (require :sb-cover) 2 | (declaim (optimize sb-cover:store-coverage-data)) 3 | (asdf:oos 'asdf:load-op :json-streams-tests :force t) 4 | (json-streams-tests::run-all-tests) 5 | (sb-cover:report "/tmp/report2/") 6 | -------------------------------------------------------------------------------- /write-float.lisp: -------------------------------------------------------------------------------- 1 | ;;;; json-streams 2 | ;;;; 3 | ;;;; Copyright (C) 2013 Thomas Bakketun 4 | ;;;; 5 | ;;;; This library is free software: you can redistribute it and/or modify 6 | ;;;; it under the terms of the GNU Lesser General Public License as published 7 | ;;;; by the Free Software Foundation, either version 3 of the License, or 8 | ;;;; (at your option) any later version. 9 | ;;;; 10 | ;;;; This library is distributed in the hope that it will be useful, 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;;;; GNU General Public License for more details. 14 | ;;;; 15 | ;;;; You should have received a copy of the GNU General Public License 16 | ;;;; along with this library. If not, see . 17 | 18 | (in-package #:json-streams) 19 | 20 | ;;; From 21 | ;;; Printing Floating-Point Numbers Quickly and Accurately 22 | ;;; by Robert G. Burger and R. Kent Dybvig 23 | 24 | (defun flonum->digits (v f e min-e p b BB) 25 | (let ((roundp (evenp f))) 26 | (if (>= e 0) 27 | (if (not (= f (expt b (- p 1)))) 28 | (let ((be (expt b e))) 29 | (scale (* f be 2) 2 be be 0 BB roundp roundp v)) 30 | (let* ((be (expt b e)) 31 | (be1 (* be b))) 32 | (scale (* f be1 2) (* b 2) be1 be 0 BB roundp roundp v))) 33 | (if (or (= e min-e) (not (= f (expt b (- p 1))))) 34 | (scale (* f 2) (* (expt b (- e)) 2) 1 1 0 BB roundp roundp v) 35 | (scale (* f b 2) (* (expt b (- 1 e)) 2) b 1 0 BB roundp roundp v))))) 36 | 37 | (defun generate (r s m+ m- BB low-ok-p high-ok-p) 38 | (multiple-value-bind (d r) 39 | (truncate (* r BB) s) 40 | (let ((m+ (* m+ BB)) 41 | (m- (* m- BB))) 42 | (let ((tc1 (funcall (if low-ok-p #'<= #'<) r m-)) 43 | (tc2 (funcall (if high-ok-p #'>= #'>) (+ r m+) s))) 44 | (if (not tc1) 45 | (if (not tc2) 46 | (cons d (generate r s m+ m- BB low-ok-p high-ok-p)) 47 | (list (+ d 1))) 48 | (if (not tc2) 49 | (list d) 50 | (if (< (* r 2) s) 51 | (list d) 52 | (list (+ d 1))))))))) 53 | 54 | (defun scale (r s m+ m- k BB low-ok-p high-ok-p v) 55 | (declare (ignore k)) 56 | (let ((est (ceiling (- (logB BB v) 1d-10)))) 57 | (if (>= est 0) 58 | (fixup r (* s (exptt BB est)) m+ m- est BB low-ok-p high-ok-p) 59 | (let ((scale (exptt BB (- est)))) 60 | (fixup (* r scale) s (* m+ scale) (* m- scale) est BB low-ok-p high-ok-p))))) 61 | 62 | (defun fixup (r s m+ m- k BB low-ok-p high-ok-p) 63 | (if (funcall (if high-ok-p #'>= #'>) (+ r m+) s) ; too low? 64 | (cons (+ k 1) (generate r (* s BB) m+ m- BB low-ok-p high-ok-p)) 65 | (cons k (generate r s m+ m- BB low-ok-p high-ok-p)))) 66 | 67 | (let ((table (make-array 326))) 68 | (do ((k 0 (+ k 1)) (v 1 (* v 10))) 69 | ((= k 326)) 70 | (setf (svref table k) v)) 71 | (defun exptt (BB k) 72 | (if (and (= BB 10) (<= 0 k 325)) 73 | (svref table k) 74 | (expt BB k)))) 75 | 76 | (let ((table (make-array 37))) 77 | (do ((BB 2 (+ BB 1))) 78 | ((= BB 37)) 79 | (setf (svref table BB) (/ (log BB)))) 80 | (defun logB (BB x) 81 | (if (<= 2 BB 36) 82 | (* (log x) (svref table BB)) 83 | (/ (log x) (log BB))))) 84 | 85 | (defconstant +min-e+ (1+ (nth-value 1 (integer-decode-float least-positive-normalized-double-float)))) 86 | (defconstant +precision+ (float-digits 0d0)) 87 | (defconstant +float-radix+ 2) 88 | (defconstant +output-base+ 10) 89 | 90 | (defun write-float (float stream) 91 | (multiple-value-bind (f e s) 92 | (integer-decode-float float) 93 | (destructuring-bind (exp &rest digits) 94 | (flonum->digits (abs float) f e +min-e+ +precision+ +float-radix+ +output-base+) 95 | (when (minusp s) 96 | (princ "-" stream)) 97 | (if (and (< (length digits) 16) 98 | (<= -2 exp 8)) 99 | (if (plusp exp) 100 | (format stream "~{~D~}.~{~D~}" (subseq digits 0 exp) (subseq digits exp)) 101 | (format stream "0.~v@{0~}~{~D~}" (abs exp) digits)) 102 | (format stream "~D.~:[0~;~:*~{~D~}~]E~D" (first digits) (rest digits) (1- exp)))))) 103 | --------------------------------------------------------------------------------