├── .cargo └── config ├── .github ├── FUNDING.yml └── workflows │ ├── audit.yml │ ├── benches.yml │ ├── coverage.yml │ ├── docs.yml │ └── rust.yml ├── .gitignore ├── .rustme ├── config.ron ├── docs.md └── header.md ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benchmarks ├── Cargo.toml └── benches │ └── benchmarks.rs ├── deny.toml ├── examples ├── borrowed-value.rs └── heapless.rs ├── fuzz ├── .gitignore ├── Cargo.lock ├── Cargo.toml └── fuzz_targets │ ├── basic.rs │ └── binary.rs ├── rustfmt.toml ├── src ├── .crate-docs.md ├── anystr.rs ├── doc.rs ├── error.rs ├── lib.rs ├── number.rs ├── parser.rs ├── string.rs ├── tests.rs └── value.rs ├── tests ├── JSONTestSuite │ ├── 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_lone_continuation_byte_in_key_and_trailing_comma.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_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_ctrl_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+FFFF.json │ ├── y_string_null_escape.json │ ├── y_string_one-byte-utf-8.json │ ├── y_string_pi.json │ ├── y_string_reservedCharacterInUTF-8_U+1BFFF.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 ├── jsonorg.rs ├── jsonorg │ ├── fail1.json │ ├── fail10.json │ ├── fail11.json │ ├── fail12.json │ ├── fail13.json │ ├── fail14.json │ ├── fail15.json │ ├── fail16.json │ ├── fail17.json │ ├── fail18.json │ ├── fail19.json │ ├── fail2.json │ ├── fail20.json │ ├── fail21.json │ ├── fail22.json │ ├── fail23.json │ ├── fail24.json │ ├── fail25.json │ ├── fail26.json │ ├── fail27.json │ ├── fail28.json │ ├── fail29.json │ ├── fail3.json │ ├── fail30.json │ ├── fail31.json │ ├── fail32.json │ ├── fail33.json │ ├── fail4.json │ ├── fail5.json │ ├── fail6.json │ ├── fail7.json │ ├── fail8.json │ ├── fail9.json │ ├── pass1.json │ ├── pass2.json │ └── pass3.json ├── jsontestsuite.rs ├── roundtrip.rs └── roundtrip │ ├── roundtrip01.json │ ├── roundtrip02.json │ ├── roundtrip03.json │ ├── roundtrip04.json │ ├── roundtrip05.json │ ├── roundtrip06.json │ ├── roundtrip07.json │ ├── roundtrip08.json │ ├── roundtrip09.json │ ├── roundtrip10.json │ ├── roundtrip11.json │ ├── roundtrip12.json │ ├── roundtrip13.json │ ├── roundtrip14.json │ ├── roundtrip15.json │ ├── roundtrip16.json │ ├── roundtrip17.json │ ├── roundtrip18.json │ ├── roundtrip19.json │ ├── roundtrip20.json │ ├── roundtrip21.json │ ├── roundtrip22.json │ ├── roundtrip23.json │ ├── roundtrip24.json │ ├── roundtrip25.json │ ├── roundtrip26.json │ └── roundtrip27.json └── xtask ├── Cargo.toml └── src └── main.rs /.cargo/config: -------------------------------------------------------------------------------- 1 | 2 | [alias] 3 | xtask = "run --package xtask --" -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [ecton] -------------------------------------------------------------------------------- /.github/workflows/audit.yml: -------------------------------------------------------------------------------- 1 | name: Audit 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | audit: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - name: Install Rust 11 | uses: hecrj/setup-rust-action@v1 12 | - name: Cache 13 | uses: actions/cache@v3 14 | with: 15 | path: | 16 | ~/.cargo/.crates.toml 17 | ~/.cargo/.crates2.json 18 | ~/.cargo/bin/cargo-deny 19 | key: cargo-deny 20 | 21 | - name: Install cargo-deny 22 | run: cargo -v install cargo-deny 23 | 24 | - name: Checkout 25 | uses: actions/checkout@v3 26 | 27 | - name: Audit 28 | run: | 29 | cargo xtask audit 30 | -------------------------------------------------------------------------------- /.github/workflows/benches.yml: -------------------------------------------------------------------------------- 1 | name: Benchmarks 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | benchmark: 7 | runs-on: ubuntu-latest 8 | timeout-minutes: 60 9 | steps: 10 | - uses: actions/checkout@v3 11 | 12 | - name: Install Rust 13 | uses: hecrj/setup-rust-action@v1 14 | 15 | - name: Build benchmarks 16 | run: | 17 | cargo bench -p benchmarks --all-features --no-run 18 | env: 19 | RUSTFLAGS: "-C target-cpu=native" 20 | 21 | - name: Run benchmarks 22 | run: | 23 | cargo bench -p benchmarks --all-features 24 | env: 25 | RUSTFLAGS: "-C target-cpu=native" 26 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: Coverage 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | coverage: 7 | runs-on: ubuntu-latest 8 | timeout-minutes: 30 9 | steps: 10 | - uses: actions/checkout@v3 11 | 12 | - name: Install Rust 13 | uses: hecrj/setup-rust-action@v1 14 | 15 | - name: Run code coverage 16 | run: | 17 | cargo xtask generate-code-coverage-report --install-dependencies 18 | env: 19 | RUSTFLAGS: "-C target-cpu=native" 20 | 21 | - name: Deploy Docs 22 | if: github.ref == 'refs/heads/main' 23 | uses: JamesIves/github-pages-deploy-action@releases/v4 24 | with: 25 | branch: gh-pages 26 | folder: coverage/ 27 | git-config-name: kl-botsu 28 | git-config-email: botsu@khonsulabs.com 29 | target-folder: /coverage/ 30 | clean: true 31 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Docs 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | docs: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Install Rust 10 | uses: hecrj/setup-rust-action@v1 11 | with: 12 | rust-version: nightly 13 | 14 | - uses: actions/checkout@v3 15 | - name: Generate Docs 16 | run: | 17 | cargo +nightly doc --no-deps --all-features 18 | 19 | - name: Deploy Docs 20 | if: github.ref == 'refs/heads/main' 21 | uses: JamesIves/github-pages-deploy-action@releases/v4 22 | with: 23 | branch: gh-pages 24 | folder: target/doc/ 25 | git-config-name: kl-botsu 26 | git-config-email: botsu@khonsulabs.com 27 | target-folder: /main/ 28 | clean: true 29 | -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | timeout-minutes: 30 9 | steps: 10 | - uses: actions/checkout@v3 11 | 12 | - name: Install Rust 13 | uses: hecrj/setup-rust-action@v1 14 | 15 | - name: Run clippy (all features) 16 | run: | 17 | cargo clippy --features heapless 18 | 19 | - name: Run clippy (no features) 20 | run: | 21 | cargo clippy --no-default-features 22 | 23 | - name: Run clippy (alloc) 24 | run: | 25 | cargo clippy --no-default-features --features alloc 26 | 27 | - name: Run clippy (heapless) 28 | run: | 29 | cargo clippy --no-default-features --features heapless 30 | 31 | # Do not pass --all-features, as it enables the "nightly" flag. 32 | - name: Run unit tests 33 | run: | 34 | cargo test --all-targets --features heapless 35 | 36 | build-msrv: 37 | name: Test on MSRV 38 | runs-on: ubuntu-latest 39 | steps: 40 | - uses: actions/checkout@v3 41 | - name: Install Rust 42 | uses: hecrj/setup-rust-action@v1 43 | with: 44 | rust-version: 1.65 45 | - name: Run unit tests 46 | run: cargo test --all-targets --features heapless 47 | 48 | build-nostd: 49 | name: Build on no_std target (thumbv7em-none-eabi) 50 | runs-on: ubuntu-latest 51 | steps: 52 | - uses: actions/checkout@v3 53 | - uses: dtolnay/rust-toolchain@master 54 | with: 55 | toolchain: stable 56 | targets: thumbv7em-none-eabi 57 | - run: cargo build --target thumbv7em-none-eabi --lib --release --no-default-features 58 | 59 | build-alloc: 60 | name: Build on no_std target (thumbv7em-none-eabi) 61 | runs-on: ubuntu-latest 62 | steps: 63 | - uses: actions/checkout@v3 64 | - uses: dtolnay/rust-toolchain@master 65 | with: 66 | toolchain: stable 67 | targets: thumbv7em-none-eabi 68 | - run: cargo build --target thumbv7em-none-eabi --lib --release --no-default-features --features alloc 69 | 70 | build-heapless: 71 | name: Build on no_std target (thumbv7em-none-eabi) 72 | runs-on: ubuntu-latest 73 | steps: 74 | - uses: actions/checkout@v3 75 | - uses: dtolnay/rust-toolchain@master 76 | with: 77 | toolchain: stable 78 | targets: thumbv7em-none-eabi 79 | - run: cargo build --target thumbv7em-none-eabi --lib --release --no-default-features --features heapless 80 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | perf.data* 3 | .vscode/ 4 | coverage/ -------------------------------------------------------------------------------- /.rustme/config.ron: -------------------------------------------------------------------------------- 1 | Configuration( 2 | files: { 3 | "../README.md": [ 4 | "header.md", 5 | "docs.md", 6 | "https://github.com/khonsulabs/.github/raw/main/snippets/readme-footer.md", 7 | ], 8 | "../src/.crate-docs.md": ( 9 | for_docs: true, 10 | sections: [ 11 | "docs.md", 12 | ] 13 | ), 14 | "../CONTRIBUTING.md": [ 15 | "https://github.com/khonsulabs/.github/raw/main/docs/CONTRIBUTING.md", 16 | ], 17 | "../CODE_OF_CONDUCT.md": [ 18 | "https://github.com/khonsulabs/.github/raw/main/docs/CODE_OF_CONDUCT.md", 19 | ], 20 | "../LICENSE-APACHE": [ 21 | "https://github.com/khonsulabs/.github/raw/main/licenses/LICENSE-APACHE", 22 | ], 23 | "../LICENSE-MIT": [ 24 | "https://github.com/khonsulabs/.github/raw/main/licenses/LICENSE-MIT", 25 | ], 26 | }, 27 | glossaries: [ 28 | "https://github.com/khonsulabs/.github/raw/main/snippets/glossary.ron", 29 | { 30 | "docs-base": ( 31 | default: "https://khonsulabs.github.io/justjson/main/justjson", 32 | release: "https://docs.rs/justjson", 33 | ), 34 | "src-base": ( 35 | default: "https://github.com/khonsulabs/justjson/blob/main", 36 | release: "https://github.com/khonsulabs/justjson/blob/v0.1.1", 37 | ), 38 | "value": ( 39 | default: "https://khonsulabs.github.io/justjson/main/justjson/enum.Value.html", 40 | release: "https://docs.rs/justjson/*/justjson/enum.Value.html", 41 | for_docs: "crate::Value", 42 | ), 43 | "string": ( 44 | default: "https://khonsulabs.github.io/justjson/main/justjson/struct.JsonString.html", 45 | release: "https://docs.rs/justjson/*/justjson/struct.JsonString.html", 46 | for_docs: "crate::JsonString", 47 | ), 48 | "number": ( 49 | default: "https://khonsulabs.github.io/justjson/main/justjson/struct.JsonNumber.html", 50 | release: "https://docs.rs/justjson/*/justjson/struct.JsonNumber.html", 51 | for_docs: "crate::JsonNumber", 52 | ), 53 | "document": ( 54 | default: "https://khonsulabs.github.io/justjson/main/justjson/doc/type.Document.html", 55 | release: "https://docs.rs/justjson/*/justjson/doc/type.Document.html", 56 | for_docs: "crate::doc::Document", 57 | ), 58 | "heapless-document": ( 59 | default: "https://khonsulabs.github.io/justjson/main/justjson/doc/type.HeaplessDocument.html", 60 | release: "https://docs.rs/justjson/*/justjson/doc/type.HeaplessDocument.html", 61 | for_docs: "crate::doc::HeaplessDocument", 62 | ), 63 | "generic-document": ( 64 | default: "https://khonsulabs.github.io/justjson/main/justjson/doc/struct.GenericDocument.html", 65 | release: "https://docs.rs/justjson/*/justjson/doc/struct.GenericDocument.html", 66 | for_docs: "crate::doc::GenericDocument", 67 | ) 68 | } 69 | ], 70 | ) -------------------------------------------------------------------------------- /.rustme/docs.md: -------------------------------------------------------------------------------- 1 | [![crate version](https://img.shields.io/crates/v/justjson.svg)](https://crates.io/crates/justjson) 2 | [![Live Build Status](https://img.shields.io/github/actions/workflow/status/khonsulabs/justjson/rust.yml?branch=main)](https://github.com/khonsulabs/justjson/actions?query=workflow:Tests) 3 | [![HTML Coverage Report for `main` branch](https://khonsulabs.github.io/justjson/coverage/badge.svg)](https://khonsulabs.github.io/justjson/coverage/) 4 | [![Documentation](https://img.shields.io/badge/docs-main-informational)]($docs-base$) 5 | 6 | An efficient JSON [`Value`][value] crate for Rust. 7 | 8 | **This crate is thoroughly tested, but it's still very early in development. 9 | Feedback is greatly appreciated.** 10 | 11 | ## Why another JSON library? 12 | 13 | This library is for developers who: 14 | 15 | - Are working with JSON, but either don't want to or can't use `serde`. 16 | - Want to parse a JSON Value from a slice with minimal allocations. 17 | 18 | If neither of those situations apply to you, you should seriously consider using 19 | `serde` and [`serde-json`][serde-json] or [`simd-json`][simd-json]. 20 | 21 | What real-world case does this use case fit? Parsing [JSON-LD Compacted Document 22 | Form][json-ld] requires inspecting the JSON to find the `@context` field, and 23 | using the information within the `@context` field to interpret the rest of the 24 | document. This form of JSON-LD representation is used by 25 | [ActivityPub][activitypub], which is a protocol that power [the 26 | Fediverse][fediverse]. 27 | 28 | ## What makes JustJson interesting? 29 | 30 | The optimal use case for JustJson is when parsing an `&str` or `&[u8]`. When 31 | parsing either of these, the returned [`Value`][value] type is `Value<&str>`. All strings 32 | and numbers are kept in their original form in the [`JsonString`][string] and 33 | [`JsonNumber`][number] types. While they are kept in their original form, they 34 | are fully validated when parsed. **The net effect is significantly fewer 35 | allocations when parsing a JSON value.** 36 | 37 | [`JsonString`][string] implements `PartialEq<&str>`/`PartialCmp<&str>` such that 38 | if the `JsonString` contains escape sequences, the comparison is handled 39 | correctly. Each `JsonString` tracks its decoded length as well as whether any 40 | escapes are present, allowing this comparison to be very efficient. 41 | 42 | ```rust 43 | let json = justjson::JsonString::from_json("\"Hello, World!\"").unwrap(); 44 | assert_eq!(json, "Hello, World!"); 45 | ``` 46 | 47 | JustJson also offers an even faster method for parsing: [`Document`][document]. 48 | When parsing an array or an object into a `Value`, the parser doesn't know how 49 | large each array or object will be until it parses the rest of the object. 50 | `Document` builds a tree representing the JSON value in a single `Vec`, further 51 | reducing the number of allocations needed when parsing a document. 52 | 53 | This extra speed comes at the expense of an API that requires iteration to 54 | inspect the `Document`. 55 | 56 | ## Benchmarks 57 | 58 | You can run the benchmarks by executing `RUSTFLAGS="-C target-cpu=native" cargo 59 | bench -p benchmarks --all-features`. There currently is only a single benchmark, 60 | testing a small JSON payload in both pretty and compact representations. 61 | 62 | ```text 63 | small-pretty/justjson/str 64 | time: [802.34 ns 804.91 ns 807.35 ns] 65 | small-pretty/justjson/doc/str 66 | time: [603.15 ns 607.13 ns 611.21 ns] 67 | small-pretty/justjson/bytes 68 | time: [774.45 ns 775.84 ns 777.37 ns] 69 | small-pretty/justjson/doc/bytes 70 | time: [688.51 ns 696.55 ns 705.09 ns] 71 | small-pretty/serde-json/str 72 | time: [860.82 ns 862.12 ns 863.43 ns] 73 | small-pretty/serde-json/bytes 74 | time: [917.49 ns 920.17 ns 923.26 ns] 75 | small-pretty/simd-json/bytes 76 | time: [702.67 ns 704.71 ns 706.61 ns] 77 | small-pretty/json-deserializer/bytes 78 | time: [858.81 ns 861.37 ns 864.88 ns] 79 | 80 | small/justjson/str time: [736.80 ns 739.94 ns 743.56 ns] 81 | small/justjson/doc/str time: [611.54 ns 618.64 ns 625.15 ns] 82 | small/justjson/bytes time: [710.26 ns 711.53 ns 712.86 ns] 83 | small/justjson/doc/bytes 84 | time: [588.97 ns 594.66 ns 600.98 ns] 85 | small/serde-json/str time: [831.89 ns 833.17 ns 834.69 ns] 86 | small/serde-json/bytes time: [874.84 ns 876.26 ns 877.90 ns] 87 | small/simd-json/bytes time: [690.41 ns 691.48 ns 692.79 ns] 88 | small/json-deserializer/bytes 89 | time: [778.87 ns 779.85 ns 780.85 ns] 90 | ``` 91 | 92 | ## Usage of Unsafe Code 93 | 94 | This crate uses unsafe code only when converting from raw incoming data to UTF-8 95 | data. The parser fully verifies that the data is valid UTF-8 before these 96 | functions are used. 97 | 98 | ## `no_std` support 99 | 100 | By default, this crate enables the `std` feature, which adds support for Rust's 101 | standard library types. By disabling default features, this crate can be used in 102 | `no_std` projects. For example, in your Cargo.toml: 103 | 104 | ```toml 105 | [dependencies] 106 | justjson = { version = "*", default-features = false } 107 | ``` 108 | 109 | The [`Value`][value] type requires the `alloc` feature to be enabled. 110 | 111 | The [`Document`][document] type alias requires the `alloc` feature, but the 112 | [`GenericDocument`][generic-doc] type allows providing your own collection type. 113 | 114 | With the `heapless` feature enabled, the [`HeaplessDocument`][heapless-doc] type 115 | can be used to parse documents using the [heapless][heapless] crate's `Vec` type 116 | for storage. This enables parsing JSON in environments where the `alloc` crate 117 | isn't supported. 118 | 119 | [value]: $value$ 120 | [string]: $string$ 121 | [number]: $number$ 122 | [document]: $document$ 123 | [generic-doc]: $generic-document$ 124 | [heapless-doc]: $heapless-document$ 125 | [json-ld]: https://www.w3.org/TR/json-ld11/#compacted-document-form 126 | [fediverse]: https://en.wikipedia.org/wiki/Fediverse 127 | [activitypub]: https://www.w3.org/TR/activitypub/ 128 | [simd-json]: https://github.com/simd-lite/simd-json 129 | [serde-json]: https://github.com/serde-rs/json 130 | [heapless]: https://github.com/japaric/heapless 131 | -------------------------------------------------------------------------------- /.rustme/header.md: -------------------------------------------------------------------------------- 1 | # justjson 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## Unreleased 9 | 10 | ### Added 11 | 12 | - `JsonNumber` and `Value` now have these additional helpers for converting to 13 | native numeric types: 14 | 15 | - `as_u8` 16 | - `as_u16` 17 | - `as_u32` 18 | - `as_u64` 19 | - `as_u128` 20 | - `as_usize` 21 | - `as_i8` 22 | - `as_i16` 23 | - `as_i32` 24 | - `as_i64` 25 | - `as_i128` 26 | - `as_isize` 27 | - `as_f32` 28 | - `as_f64` 29 | 30 | - `JsonNumber::parse()` is a new function that uses a types `FromStr` 31 | implementation to parse the source of the numeric literal. 32 | 33 | ## v0.2.3 (2023-04-11) 34 | 35 | ### Changed 36 | 37 | - This crate's MSRV has been changed to 1.65. This is not a breaking change, 38 | however, as the crate never supported its advertised MSRV, and this new MSRV 39 | reflects what the true MSRV has always been. An additional CI pass was added 40 | to ensure the MSRV is always tested against. Thanks to @hr8 in #8 for 41 | reporting this. 42 | 43 | ### Added 44 | 45 | - `AnyStr::as_str()` has been added, which acts the same as 46 | `AsRef`/`Borrow`/`Deref`. 47 | - `JsonString::as_str()` has been added, which will return an `&str` to the 48 | contained string, if it doesn't contain escape sequences. If the string has 49 | escape sequences, None will be returned. 50 | - `Value::as_str()` has been added, which will return an `&str` to the contained 51 | string if the the `Value` is a `JsonString` that has no escape sequences. If 52 | the value is not a string or it has escape sequences, None will be returned. 53 | 54 | Thanks to @hr8 in #9 for requesting this. 55 | - `JsonString` now implements `Display` with the decoded representation. This 56 | also means that `ToString` is now implemented such that it produces a decoded 57 | string. 58 | - `Tokenizer` is a new low-level parsing type that provides basic tokenization. 59 | Thank you to @indietyp in #13 for refactoring the parser to expose this 60 | functionality! 61 | 62 | ## v0.2.2 (2023-02-02) 63 | 64 | ### Added 65 | 66 | - `JsonString` now implements `Ord`, `PartialOrd`, and `PartialOrd`, and 67 | `Hash`. 68 | - `Entry`, the type which `Object` is a collection of, is now exported. This was 69 | an oversight. Thanks to @PoiScript for reporting this in #6. 70 | - `Value::get(key)`, `Value::get_mut(key)`, and `Index<&str>`/`IndexMut<&str>` 71 | have been added to allow easier access to the contents of a `Value` when it is 72 | an object. Similar to most built-in collection types, the `Index` trait 73 | implementations will panic if the key is not found, but the `get` variants 74 | return an Option instead of panicking. 75 | - `Value::get_index(usize)`, `Value::get_index_mut(usize)`, and 76 | `Index`/`IndexMut` have been added to allow easier access to the 77 | contents of a `Value` when it is an array. Similar to most built-in collection 78 | types, the `Index` trait implementations will panic if the index is out of 79 | bounds, but the `get_index` variants return an Option instead of panicking. 80 | - `From<&str>`, `From`, `From>`, `From>`, and 81 | `From` have been implemented for `Value<'_>`. 82 | 83 | ## v0.2.1 (2023-01-25) 84 | 85 | This release contains no code changes. The `Cargo.toml` section for docs.rs has 86 | been updated in an attempt to enable `doc_auto_cfg`, which annotates what 87 | features flags are needed for any given item in the documentation. 88 | 89 | ## v0.2.0 (2023-01-25) 90 | 91 | ### Breaking Changes 92 | 93 | - `Value`, `Object`, `JsonNumber`, and `JsonString` have all changed from having 94 | a generic parameter to having a single lifetime parameter. Internally, all 95 | strings have been changed to `Cow<'_, str>` to allow for owned values to be 96 | injected into a `Value`/`Object` or `Vec>`. 97 | - `JsonString::source` has been removed from the public API. 98 | `JsonString::contents()` is now available to provide read-only access to the 99 | JSON-encoded representation. 100 | - `JsonNumber::source` has been removed from the public API. 101 | `JsonNumber::source()` is now available to provide read-only access to the 102 | JSON-encoded representation. 103 | - `JsonString` now internally can be a JSON-encoded string or a raw string, and 104 | it will encode or decode escape sequences on the fly as needed. This means 105 | adding a new raw &str that needs escaping will not actually incur extra 106 | allocations while rendering a Value back to JSON, as the encoding operation 107 | will occur during the write to the destination. 108 | - `Object::push()` has been removed, and its `Deref` implementation now targets 109 | `Vec>`. This allows all `Vec` methods to be used to access the 110 | contents of an Object, including its own `push()` function. 111 | - `ParseDelegate::Error` is a new associated type that is now able to be 112 | returned from most `ParseDelegate` functions as the Error type of the Result. 113 | Previously, most functions did not return a Result. 114 | 115 | Returning an error from a `ParseDelegate` function will stop parsing the 116 | underlying document immediately and return the error in 117 | `ErrorKind::ErrorFromDelegate`. 118 | 119 | ### Fixes 120 | 121 | - Escaped UTF16 surrogate pairs are properly handled. Previously, all surrogates 122 | were considered invalid unicode. 123 | - Leading `+` signs are no longer allowed on numbers. 124 | - Leading `0`s are now disallowed on negative numbers. 125 | 126 | ### Added 127 | 128 | - `JsonString::from(&str)` has been added to convert from a Rust string to its 129 | JSON-encoded form. 130 | - This crate now is `no_std` compatible. The `no_std` support is controlled by 131 | three feature flags: 132 | 133 | - `std`: Enabled by default, enables `alloc` automatically. 134 | - `alloc`: Uses the `alloc` crate for the `Document` and `Value` types. 135 | - `heapless`: Exports a new `HeaplessDocument` type that can be used in 136 | environments without `alloc`. 137 | 138 | Without any features enabled, only `Parser`, `GenericDocument`, `JsonString`, 139 | and `JsonNumber` are available to parse JSON. 140 | 141 | To enable `GenericDocument` to work with types other than `Vec` and 142 | `heapless::Vec`, `NodeCollection` can be implemented for other Vec-like types. 143 | 144 | ### Changed 145 | 146 | - `thiserror` has been removed from the dependencies in favor of manually 147 | implementing `std::error::Error`. This makes `justjson` dependency free 148 | without enabling extra feature flags. 149 | 150 | ## v0.1.1 (2023-01-20) 151 | 152 | ### Fixed 153 | 154 | - Fixed a panic when reporting an error during decoding of some invalid unicode 155 | escape sequences. 156 | 157 | ## v0.1.0 (2023-01-19) 158 | 159 | - Initial release 160 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | moderators@khonsulabs.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to our projects 2 | 3 | Thank you for your interest in contributing to one of our projects. We want 4 | everyone to have a positive experience contributing, so please carefully review 5 | our only requirements for contributing: 6 | 7 | - All contributors must agree to [our Contributor License 8 | Agreement](https://gist.github.com/ecton/b2e1e72abfa122da5e69ed30164f739e). 9 | This will be asked for during your first pull request. 10 | - All contributors must uphold the standards of our [Code of 11 | Conduct](./CODE_OF_CONDUCT.md). 12 | 13 | The rest of this document are recommendations/guidelines to help consistency and 14 | communication within our projects. 15 | 16 | ## Creating Issues 17 | 18 | ### Reporting Bugs 19 | 20 | To us, if something isn't behaving as you expect it to, that's a bug. Even if 21 | it's misbehaving due to a misunderstanding, that means there's an opportunity to 22 | improve our documentation or examples. Please don't hesitate to let us know if 23 | you run into any issues while working with one of our projects. 24 | 25 | ### Requesting New Features 26 | 27 | When requesting new features, please include details about what problem you're 28 | trying to solve, not just a solution to your problem. By helping the community 29 | understand the underlying problem, we can better evaluate what the best solution 30 | to the problem might be. 31 | 32 | ## Contributing Changes 33 | 34 | We openly welcome pull requests on our projects. We don't like bugs, and if 35 | you've found one and wish to submit a fix, we greatly appreciate it. 36 | 37 | If you find that fixing a bug requires a significant change, or you are wanting 38 | to add a somewhat large feature, please submit a proposal as an issue first. We 39 | want to make sure that your efforts have the highest chance of success, and a 40 | short discussion before starting can go a long way towards a pull request being 41 | merged with less revisions. 42 | 43 | When working on an existing issue, update the issue to reflect that you're 44 | working on it. This will help prevent duplicated efforts. 45 | 46 | If you begin working on something but need some assistance, don't hesitate to 47 | reach out inside of the issue, on [our 48 | forums](https://community.khonsulabs.com/), or [our 49 | Discord](https://discord.khonsulabs.com/). We will do our best to help you. 50 | 51 | ### Project-specific requirements 52 | 53 | Be sure to check if a project's README contains additional contributing 54 | guidelines. Each project may have different tools and commands that should be 55 | run to validate that changes pass all requirements. 56 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "justjson" 3 | version = "0.2.3" 4 | edition = "2021" 5 | description = "An efficient JSON Value crate that allows borrowing data." 6 | license = "MIT OR Apache-2.0" 7 | repository = "https://github.com/khonsulabs/justjson" 8 | keywords = ["json"] 9 | categories = ["parser-implementations"] 10 | readme = "./README.md" 11 | rust-version = "1.65" 12 | 13 | [features] 14 | default = ["std"] 15 | std = ["alloc"] 16 | alloc = [] 17 | nightly = [] # Enables unstable documentation features outside of docs.rs 18 | 19 | [dependencies] 20 | heapless = { version = "0.8.0", optional = true } 21 | 22 | 23 | [workspace] 24 | members = ["benchmarks", "xtask"] 25 | 26 | [profile.bench] 27 | lto = true 28 | debug = true 29 | 30 | [profile.release] 31 | lto = true 32 | debug = true 33 | 34 | [[test]] 35 | name = "roundtrip" 36 | required-features = ["alloc"] 37 | 38 | [[example]] 39 | name = "borrowed-value" 40 | required-features = ["alloc"] 41 | 42 | [[example]] 43 | name = "heapless" 44 | required-features = ["heapless"] 45 | 46 | [package.metadata.docs.rs] 47 | rustdoc-args = ["--cfg", "docsrs"] 48 | features = ["heapless"] 49 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2021 Khonsu Labs LLC 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright 2021 Khonsu Labs LLC 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # justjson 2 | 3 | [![crate version](https://img.shields.io/crates/v/justjson.svg)](https://crates.io/crates/justjson) 4 | [![Live Build Status](https://img.shields.io/github/actions/workflow/status/khonsulabs/justjson/rust.yml?branch=main)](https://github.com/khonsulabs/justjson/actions?query=workflow:Tests) 5 | [![HTML Coverage Report for `main` branch](https://khonsulabs.github.io/justjson/coverage/badge.svg)](https://khonsulabs.github.io/justjson/coverage/) 6 | [![Documentation](https://img.shields.io/badge/docs-main-informational)](https://khonsulabs.github.io/justjson/main/justjson) 7 | 8 | An efficient JSON [`Value`][value] crate for Rust. 9 | 10 | **This crate is thoroughly tested, but it's still very early in development. 11 | Feedback is greatly appreciated.** 12 | 13 | ## Why another JSON library? 14 | 15 | This library is for developers who: 16 | 17 | - Are working with JSON, but either don't want to or can't use `serde`. 18 | - Want to parse a JSON Value from a slice with minimal allocations. 19 | 20 | If neither of those situations apply to you, you should seriously consider using 21 | `serde` and [`serde-json`][serde-json] or [`simd-json`][simd-json]. 22 | 23 | What real-world case does this use case fit? Parsing [JSON-LD Compacted Document 24 | Form][json-ld] requires inspecting the JSON to find the `@context` field, and 25 | using the information within the `@context` field to interpret the rest of the 26 | document. This form of JSON-LD representation is used by 27 | [ActivityPub][activitypub], which is a protocol that power [the 28 | Fediverse][fediverse]. 29 | 30 | ## What makes JustJson interesting? 31 | 32 | The optimal use case for JustJson is when parsing an `&str` or `&[u8]`. When 33 | parsing either of these, the returned [`Value`][value] type is `Value<&str>`. All strings 34 | and numbers are kept in their original form in the [`JsonString`][string] and 35 | [`JsonNumber`][number] types. While they are kept in their original form, they 36 | are fully validated when parsed. **The net effect is significantly fewer 37 | allocations when parsing a JSON value.** 38 | 39 | [`JsonString`][string] implements `PartialEq<&str>`/`PartialCmp<&str>` such that 40 | if the `JsonString` contains escape sequences, the comparison is handled 41 | correctly. Each `JsonString` tracks its decoded length as well as whether any 42 | escapes are present, allowing this comparison to be very efficient. 43 | 44 | ```rust 45 | let json = justjson::JsonString::from_json("\"Hello, World!\"").unwrap(); 46 | assert_eq!(json, "Hello, World!"); 47 | ``` 48 | 49 | JustJson also offers an even faster method for parsing: [`Document`][document]. 50 | When parsing an array or an object into a `Value`, the parser doesn't know how 51 | large each array or object will be until it parses the rest of the object. 52 | `Document` builds a tree representing the JSON value in a single `Vec`, further 53 | reducing the number of allocations needed when parsing a document. 54 | 55 | This extra speed comes at the expense of an API that requires iteration to 56 | inspect the `Document`. 57 | 58 | ## Benchmarks 59 | 60 | You can run the benchmarks by executing `RUSTFLAGS="-C target-cpu=native" cargo 61 | bench -p benchmarks --all-features`. There currently is only a single benchmark, 62 | testing a small JSON payload in both pretty and compact representations. 63 | 64 | ```text 65 | small-pretty/justjson/str 66 | time: [802.34 ns 804.91 ns 807.35 ns] 67 | small-pretty/justjson/doc/str 68 | time: [603.15 ns 607.13 ns 611.21 ns] 69 | small-pretty/justjson/bytes 70 | time: [774.45 ns 775.84 ns 777.37 ns] 71 | small-pretty/justjson/doc/bytes 72 | time: [688.51 ns 696.55 ns 705.09 ns] 73 | small-pretty/serde-json/str 74 | time: [860.82 ns 862.12 ns 863.43 ns] 75 | small-pretty/serde-json/bytes 76 | time: [917.49 ns 920.17 ns 923.26 ns] 77 | small-pretty/simd-json/bytes 78 | time: [702.67 ns 704.71 ns 706.61 ns] 79 | small-pretty/json-deserializer/bytes 80 | time: [858.81 ns 861.37 ns 864.88 ns] 81 | 82 | small/justjson/str time: [736.80 ns 739.94 ns 743.56 ns] 83 | small/justjson/doc/str time: [611.54 ns 618.64 ns 625.15 ns] 84 | small/justjson/bytes time: [710.26 ns 711.53 ns 712.86 ns] 85 | small/justjson/doc/bytes 86 | time: [588.97 ns 594.66 ns 600.98 ns] 87 | small/serde-json/str time: [831.89 ns 833.17 ns 834.69 ns] 88 | small/serde-json/bytes time: [874.84 ns 876.26 ns 877.90 ns] 89 | small/simd-json/bytes time: [690.41 ns 691.48 ns 692.79 ns] 90 | small/json-deserializer/bytes 91 | time: [778.87 ns 779.85 ns 780.85 ns] 92 | ``` 93 | 94 | ## Usage of Unsafe Code 95 | 96 | This crate uses unsafe code only when converting from raw incoming data to UTF-8 97 | data. The parser fully verifies that the data is valid UTF-8 before these 98 | functions are used. 99 | 100 | ## `no_std` support 101 | 102 | By default, this crate enables the `std` feature, which adds support for Rust's 103 | standard library types. By disabling default features, this crate can be used in 104 | `no_std` projects. For example, in your Cargo.toml: 105 | 106 | ```toml 107 | [dependencies] 108 | justjson = { version = "*", default-features = false } 109 | ``` 110 | 111 | The [`Value`][value] type requires the `alloc` feature to be enabled. 112 | 113 | The [`Document`][document] type alias requires the `alloc` feature, but the 114 | [`GenericDocument`][generic-doc] type allows providing your own collection type. 115 | 116 | With the `heapless` feature enabled, the [`HeaplessDocument`][heapless-doc] type 117 | can be used to parse documents using the [heapless][heapless] crate's `Vec` type 118 | for storage. This enables parsing JSON in environments where the `alloc` crate 119 | isn't supported. 120 | 121 | [value]: https://khonsulabs.github.io/justjson/main/justjson/enum.Value.html 122 | [string]: https://khonsulabs.github.io/justjson/main/justjson/struct.JsonString.html 123 | [number]: https://khonsulabs.github.io/justjson/main/justjson/struct.JsonNumber.html 124 | [document]: https://khonsulabs.github.io/justjson/main/justjson/doc/type.Document.html 125 | [generic-doc]: https://khonsulabs.github.io/justjson/main/justjson/doc/struct.GenericDocument.html 126 | [heapless-doc]: https://khonsulabs.github.io/justjson/main/justjson/doc/type.HeaplessDocument.html 127 | [json-ld]: https://www.w3.org/TR/json-ld11/#compacted-document-form 128 | [fediverse]: https://en.wikipedia.org/wiki/Fediverse 129 | [activitypub]: https://www.w3.org/TR/activitypub/ 130 | [simd-json]: https://github.com/simd-lite/simd-json 131 | [serde-json]: https://github.com/serde-rs/json 132 | [heapless]: https://github.com/japaric/heapless 133 | 134 | ## Open-source Licenses 135 | 136 | This project, like all projects from [Khonsu Labs](https://khonsulabs.com/), are 137 | open-source. This repository is available under the [MIT License](./LICENSE-MIT) 138 | or the [Apache License 2.0](./LICENSE-APACHE). 139 | 140 | To learn more about contributing, please see [CONTRIBUTING.md](./CONTRIBUTING.md). 141 | -------------------------------------------------------------------------------- /benchmarks/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "benchmarks" 3 | version = "0.0.0" 4 | edition = "2021" 5 | publish = false 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | criterion = { version = "0.4.0", features = ["html_reports"] } 11 | serde_json = "1.0.91" 12 | justjson = { path = ".." } 13 | json-deserializer = "0.4.4" 14 | simd-json = { version = "0.7.0", optional = true } 15 | 16 | 17 | [[bench]] 18 | name = "benchmarks" 19 | harness = false 20 | -------------------------------------------------------------------------------- /benchmarks/benches/benchmarks.rs: -------------------------------------------------------------------------------- 1 | use criterion::measurement::WallTime; 2 | use criterion::{black_box, criterion_group, criterion_main, BenchmarkGroup, Criterion}; 3 | 4 | const SMALL_OBJECT: &str = r#"{ 5 | "@context": "https://www.w3.org/ns/activitystreams", 6 | "summary": "A note", 7 | "type": "Note", 8 | "content": "My dog has fleas.", 9 | "numbers": [1, 2, 4.4], 10 | "keywords": { 11 | "true": true, 12 | "false": false, 13 | "null": null 14 | } 15 | }"#; 16 | 17 | const SMALL_OBJECT_COMPACT: &str = r#"{"@context":"https://www.w3.org/ns/activitystreams","summary":"A note","type":"Note","content":"My dog has fleas.","numbers":[1,2,4.4],"keywords":{"true":true,"false":false,"null":null}}"#; 18 | 19 | fn justjson_parse(json: &str) -> justjson::Value<'_> { 20 | justjson::Value::from_json(json).unwrap() 21 | } 22 | 23 | fn justjson_parse_doc(json: &str) -> justjson::doc::Document<'_> { 24 | justjson::doc::Document::from_json(json).unwrap() 25 | } 26 | 27 | fn serde_json_value_parse(json: &str) -> serde_json::Value { 28 | serde_json::from_str(json).unwrap() 29 | } 30 | 31 | fn json_deserializer_parse_bytes(json: &str) -> json_deserializer::Value { 32 | json_deserializer::parse(json.as_bytes()).unwrap() 33 | } 34 | 35 | #[cfg(feature = "simd-json")] 36 | fn simd_json_parse(json: &mut Vec) { 37 | let _ = simd_json::to_borrowed_value(json).unwrap(); 38 | } 39 | 40 | fn justjson_parse_bytes(json: &str) -> justjson::Value<'_> { 41 | justjson::Value::from_json_bytes(json.as_bytes()).unwrap() 42 | } 43 | 44 | fn justjson_parse_doc_bytes(json: &str) -> justjson::doc::Document<'_> { 45 | justjson::doc::Document::from_json_bytes(json.as_bytes()).unwrap() 46 | } 47 | 48 | fn serde_json_value_parse_bytes(json: &str) -> serde_json::Value { 49 | serde_json::from_slice(json.as_bytes()).unwrap() 50 | } 51 | 52 | fn bench_with_input(mut group: BenchmarkGroup<'_, WallTime>, input: &str) { 53 | group.bench_function("justjson/str", |b| { 54 | b.iter(|| justjson_parse(black_box(input))); 55 | }); 56 | 57 | group.bench_function("justjson/doc/str", |b| { 58 | b.iter(|| justjson_parse_doc(black_box(input))); 59 | }); 60 | 61 | group.bench_function("justjson/bytes", |b| { 62 | b.iter(|| justjson_parse_bytes(black_box(input))); 63 | }); 64 | 65 | group.bench_function("justjson/doc/bytes", |b| { 66 | b.iter(|| justjson_parse_doc_bytes(black_box(input))); 67 | }); 68 | 69 | group.bench_function("serde-json/str", |b| { 70 | b.iter(|| serde_json_value_parse(black_box(input))); 71 | }); 72 | 73 | group.bench_function("serde-json/bytes", |b| { 74 | b.iter(|| serde_json_value_parse_bytes(black_box(input))); 75 | }); 76 | 77 | #[cfg(feature = "simd-json")] 78 | group.bench_function("simd-json/bytes", |b| { 79 | let mut bytes = input.as_bytes().to_vec(); 80 | b.iter(|| simd_json_parse(black_box(&mut bytes))); 81 | }); 82 | 83 | group.bench_function("json-deserializer/bytes", |b| { 84 | b.iter(|| json_deserializer_parse_bytes(black_box(input))); 85 | }); 86 | } 87 | 88 | fn benchmarks(c: &mut Criterion) { 89 | bench_with_input(c.benchmark_group("small-pretty"), SMALL_OBJECT); 90 | bench_with_input(c.benchmark_group("small"), SMALL_OBJECT_COMPACT); 91 | } 92 | 93 | criterion_group!(benches, benchmarks); 94 | criterion_main!(benches); 95 | -------------------------------------------------------------------------------- /deny.toml: -------------------------------------------------------------------------------- 1 | targets = [] 2 | 3 | [advisories] 4 | db-path = "~/.cargo/advisory-db" 5 | db-urls = ["https://github.com/rustsec/advisory-db"] 6 | vulnerability = "deny" 7 | unmaintained = "warn" 8 | yanked = "warn" 9 | notice = "warn" 10 | ignore = [] 11 | 12 | [licenses] 13 | unlicensed = "deny" 14 | allow = [] 15 | deny = [] 16 | copyleft = "deny" 17 | allow-osi-fsf-free = "either" 18 | default = "deny" 19 | confidence-threshold = 0.8 20 | exceptions = [] 21 | 22 | [licenses.private] 23 | ignore = true 24 | 25 | [bans] 26 | multiple-versions = "warn" 27 | wildcards = "allow" 28 | highlight = "all" 29 | -------------------------------------------------------------------------------- /examples/borrowed-value.rs: -------------------------------------------------------------------------------- 1 | use justjson::Value; 2 | 3 | fn main() { 4 | let value = Value::from_json(r#"{"hello":"world"}"#).expect("error parsing json"); 5 | let obj = value.as_object().expect("json contains an object"); 6 | assert_eq!(obj[0].key, "hello"); 7 | let value = obj[0].value.as_string().expect("value is a string"); 8 | assert_eq!(value, "world"); 9 | } 10 | 11 | #[test] 12 | fn runs() { 13 | main(); 14 | } 15 | -------------------------------------------------------------------------------- /examples/heapless.rs: -------------------------------------------------------------------------------- 1 | use justjson::doc::{HeaplessDocument, Node}; 2 | use justjson::{ErrorKind, JsonString}; 3 | 4 | fn main() { 5 | // Using a heapless vec, we can parse directly to the stack. 6 | let doc: HeaplessDocument<'_, 3> = 7 | HeaplessDocument::from_json(r#"{"hello": "world"}"#).expect("invalid json"); 8 | let mut nodes = doc.into_iter(); 9 | assert_eq!(nodes.next(), Some(Node::Object { length: 1 })); 10 | assert_eq!(nodes.next(), Some(Node::String(JsonString::from("hello")))); 11 | assert_eq!(nodes.next(), Some(Node::String(JsonString::from("world")))); 12 | 13 | // When parsing a document too large for the heapless Vec, an error will be 14 | // returned instead of panicing. 15 | let error = HeaplessDocument::<3>::from_json("[1, 2, 3, 4]").expect_err("shouldn't have space"); 16 | assert_eq!(error.kind(), &ErrorKind::PaylodTooLarge); 17 | } 18 | 19 | #[test] 20 | fn runs() { 21 | main(); 22 | } 23 | -------------------------------------------------------------------------------- /fuzz/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | corpus 3 | artifacts 4 | -------------------------------------------------------------------------------- /fuzz/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "arbitrary" 7 | version = "1.2.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "b0224938f92e7aef515fac2ff2d18bd1115c1394ddf4a092e0c87e8be9499ee5" 10 | 11 | [[package]] 12 | name = "cc" 13 | version = "1.0.78" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" 16 | dependencies = [ 17 | "jobserver", 18 | ] 19 | 20 | [[package]] 21 | name = "jobserver" 22 | version = "0.1.25" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" 25 | dependencies = [ 26 | "libc", 27 | ] 28 | 29 | [[package]] 30 | name = "justjson" 31 | version = "0.1.0" 32 | dependencies = [ 33 | "thiserror", 34 | ] 35 | 36 | [[package]] 37 | name = "justjson-fuzz" 38 | version = "0.0.0" 39 | dependencies = [ 40 | "justjson", 41 | "libfuzzer-sys", 42 | ] 43 | 44 | [[package]] 45 | name = "libc" 46 | version = "0.2.139" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" 49 | 50 | [[package]] 51 | name = "libfuzzer-sys" 52 | version = "0.4.5" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "c8fff891139ee62800da71b7fd5b508d570b9ad95e614a53c6f453ca08366038" 55 | dependencies = [ 56 | "arbitrary", 57 | "cc", 58 | "once_cell", 59 | ] 60 | 61 | [[package]] 62 | name = "once_cell" 63 | version = "1.17.0" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" 66 | 67 | [[package]] 68 | name = "proc-macro2" 69 | version = "1.0.50" 70 | source = "registry+https://github.com/rust-lang/crates.io-index" 71 | checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" 72 | dependencies = [ 73 | "unicode-ident", 74 | ] 75 | 76 | [[package]] 77 | name = "quote" 78 | version = "1.0.23" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" 81 | dependencies = [ 82 | "proc-macro2", 83 | ] 84 | 85 | [[package]] 86 | name = "syn" 87 | version = "1.0.107" 88 | source = "registry+https://github.com/rust-lang/crates.io-index" 89 | checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" 90 | dependencies = [ 91 | "proc-macro2", 92 | "quote", 93 | "unicode-ident", 94 | ] 95 | 96 | [[package]] 97 | name = "thiserror" 98 | version = "1.0.38" 99 | source = "registry+https://github.com/rust-lang/crates.io-index" 100 | checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" 101 | dependencies = [ 102 | "thiserror-impl", 103 | ] 104 | 105 | [[package]] 106 | name = "thiserror-impl" 107 | version = "1.0.38" 108 | source = "registry+https://github.com/rust-lang/crates.io-index" 109 | checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" 110 | dependencies = [ 111 | "proc-macro2", 112 | "quote", 113 | "syn", 114 | ] 115 | 116 | [[package]] 117 | name = "unicode-ident" 118 | version = "1.0.6" 119 | source = "registry+https://github.com/rust-lang/crates.io-index" 120 | checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" 121 | -------------------------------------------------------------------------------- /fuzz/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "justjson-fuzz" 3 | version = "0.0.0" 4 | authors = ["Automatically generated"] 5 | publish = false 6 | edition = "2018" 7 | 8 | [package.metadata] 9 | cargo-fuzz = true 10 | 11 | [dependencies] 12 | libfuzzer-sys = "0.4" 13 | 14 | [dependencies.justjson] 15 | path = ".." 16 | 17 | # Prevent this from interfering with workspaces 18 | [workspace] 19 | members = ["."] 20 | 21 | [[bin]] 22 | name = "basic" 23 | path = "fuzz_targets/basic.rs" 24 | test = false 25 | doc = false 26 | 27 | [[bin]] 28 | name = "binary" 29 | path = "fuzz_targets/binary.rs" 30 | test = false 31 | doc = false 32 | -------------------------------------------------------------------------------- /fuzz/fuzz_targets/basic.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | 3 | use libfuzzer_sys::fuzz_target; 4 | 5 | use justjson::Value; 6 | 7 | fuzz_target!(|data: &str| { 8 | let _ = Value::from_json(data); 9 | }); 10 | -------------------------------------------------------------------------------- /fuzz/fuzz_targets/binary.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | 3 | use libfuzzer_sys::fuzz_target; 4 | 5 | use justjson::Value; 6 | 7 | fuzz_target!(|data: &[u8]| { 8 | let _ = Value::from_json_bytes(data); 9 | }); 10 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | unstable_features = true 2 | use_field_init_shorthand = true 3 | imports_granularity = "Module" 4 | group_imports = "StdExternalCrate" 5 | format_code_in_doc_comments = true 6 | reorder_impl_items = true 7 | -------------------------------------------------------------------------------- /src/.crate-docs.md: -------------------------------------------------------------------------------- 1 | [![crate version](https://img.shields.io/crates/v/justjson.svg)](https://crates.io/crates/justjson) 2 | [![Live Build Status](https://img.shields.io/github/actions/workflow/status/khonsulabs/justjson/rust.yml?branch=main)](https://github.com/khonsulabs/justjson/actions?query=workflow:Tests) 3 | [![HTML Coverage Report for `main` branch](https://khonsulabs.github.io/justjson/coverage/badge.svg)](https://khonsulabs.github.io/justjson/coverage/) 4 | [![Documentation](https://img.shields.io/badge/docs-main-informational)](https://khonsulabs.github.io/justjson/main/justjson) 5 | 6 | An efficient JSON [`Value`][value] crate for Rust. 7 | 8 | **This crate is thoroughly tested, but it's still very early in development. 9 | Feedback is greatly appreciated.** 10 | 11 | ## Why another JSON library? 12 | 13 | This library is for developers who: 14 | 15 | - Are working with JSON, but either don't want to or can't use `serde`. 16 | - Want to parse a JSON Value from a slice with minimal allocations. 17 | 18 | If neither of those situations apply to you, you should seriously consider using 19 | `serde` and [`serde-json`][serde-json] or [`simd-json`][simd-json]. 20 | 21 | What real-world case does this use case fit? Parsing [JSON-LD Compacted Document 22 | Form][json-ld] requires inspecting the JSON to find the `@context` field, and 23 | using the information within the `@context` field to interpret the rest of the 24 | document. This form of JSON-LD representation is used by 25 | [ActivityPub][activitypub], which is a protocol that power [the 26 | Fediverse][fediverse]. 27 | 28 | ## What makes JustJson interesting? 29 | 30 | The optimal use case for JustJson is when parsing an `&str` or `&[u8]`. When 31 | parsing either of these, the returned [`Value`][value] type is `Value<&str>`. All strings 32 | and numbers are kept in their original form in the [`JsonString`][string] and 33 | [`JsonNumber`][number] types. While they are kept in their original form, they 34 | are fully validated when parsed. **The net effect is significantly fewer 35 | allocations when parsing a JSON value.** 36 | 37 | [`JsonString`][string] implements `PartialEq<&str>`/`PartialCmp<&str>` such that 38 | if the `JsonString` contains escape sequences, the comparison is handled 39 | correctly. Each `JsonString` tracks its decoded length as well as whether any 40 | escapes are present, allowing this comparison to be very efficient. 41 | 42 | ```rust 43 | let json = justjson::JsonString::from_json("\"Hello, World!\"").unwrap(); 44 | assert_eq!(json, "Hello, World!"); 45 | ``` 46 | 47 | JustJson also offers an even faster method for parsing: [`Document`][document]. 48 | When parsing an array or an object into a `Value`, the parser doesn't know how 49 | large each array or object will be until it parses the rest of the object. 50 | `Document` builds a tree representing the JSON value in a single `Vec`, further 51 | reducing the number of allocations needed when parsing a document. 52 | 53 | This extra speed comes at the expense of an API that requires iteration to 54 | inspect the `Document`. 55 | 56 | ## Benchmarks 57 | 58 | You can run the benchmarks by executing `RUSTFLAGS="-C target-cpu=native" cargo 59 | bench -p benchmarks --all-features`. There currently is only a single benchmark, 60 | testing a small JSON payload in both pretty and compact representations. 61 | 62 | ```text 63 | small-pretty/justjson/str 64 | time: [802.34 ns 804.91 ns 807.35 ns] 65 | small-pretty/justjson/doc/str 66 | time: [603.15 ns 607.13 ns 611.21 ns] 67 | small-pretty/justjson/bytes 68 | time: [774.45 ns 775.84 ns 777.37 ns] 69 | small-pretty/justjson/doc/bytes 70 | time: [688.51 ns 696.55 ns 705.09 ns] 71 | small-pretty/serde-json/str 72 | time: [860.82 ns 862.12 ns 863.43 ns] 73 | small-pretty/serde-json/bytes 74 | time: [917.49 ns 920.17 ns 923.26 ns] 75 | small-pretty/simd-json/bytes 76 | time: [702.67 ns 704.71 ns 706.61 ns] 77 | small-pretty/json-deserializer/bytes 78 | time: [858.81 ns 861.37 ns 864.88 ns] 79 | 80 | small/justjson/str time: [736.80 ns 739.94 ns 743.56 ns] 81 | small/justjson/doc/str time: [611.54 ns 618.64 ns 625.15 ns] 82 | small/justjson/bytes time: [710.26 ns 711.53 ns 712.86 ns] 83 | small/justjson/doc/bytes 84 | time: [588.97 ns 594.66 ns 600.98 ns] 85 | small/serde-json/str time: [831.89 ns 833.17 ns 834.69 ns] 86 | small/serde-json/bytes time: [874.84 ns 876.26 ns 877.90 ns] 87 | small/simd-json/bytes time: [690.41 ns 691.48 ns 692.79 ns] 88 | small/json-deserializer/bytes 89 | time: [778.87 ns 779.85 ns 780.85 ns] 90 | ``` 91 | 92 | ## Usage of Unsafe Code 93 | 94 | This crate uses unsafe code only when converting from raw incoming data to UTF-8 95 | data. The parser fully verifies that the data is valid UTF-8 before these 96 | functions are used. 97 | 98 | ## `no_std` support 99 | 100 | By default, this crate enables the `std` feature, which adds support for Rust's 101 | standard library types. By disabling default features, this crate can be used in 102 | `no_std` projects. For example, in your Cargo.toml: 103 | 104 | ```toml 105 | [dependencies] 106 | justjson = { version = "*", default-features = false } 107 | ``` 108 | 109 | The [`Value`][value] type requires the `alloc` feature to be enabled. 110 | 111 | The [`Document`][document] type alias requires the `alloc` feature, but the 112 | [`GenericDocument`][generic-doc] type allows providing your own collection type. 113 | 114 | With the `heapless` feature enabled, the [`HeaplessDocument`][heapless-doc] type 115 | can be used to parse documents using the [heapless][heapless] crate's `Vec` type 116 | for storage. This enables parsing JSON in environments where the `alloc` crate 117 | isn't supported. 118 | 119 | [value]: crate::Value 120 | [string]: crate::JsonString 121 | [number]: crate::JsonNumber 122 | [document]: crate::doc::Document 123 | [generic-doc]: crate::doc::GenericDocument 124 | [heapless-doc]: crate::doc::HeaplessDocument 125 | [json-ld]: https://www.w3.org/TR/json-ld11/#compacted-document-form 126 | [fediverse]: https://en.wikipedia.org/wiki/Fediverse 127 | [activitypub]: https://www.w3.org/TR/activitypub/ 128 | [simd-json]: https://github.com/simd-lite/simd-json 129 | [serde-json]: https://github.com/serde-rs/json 130 | [heapless]: https://github.com/japaric/heapless 131 | -------------------------------------------------------------------------------- /src/anystr.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "alloc")] 2 | use alloc::string::String; 3 | use core::borrow::Borrow; 4 | use core::hash::Hash; 5 | use core::ops::Deref; 6 | 7 | /// A string that can be either Owned or Borrowed. 8 | /// 9 | /// This type is similar to the standard library's Cow, but the `Owned` variant 10 | /// is only available when the `alloc` or `std` features are enabled. 11 | #[derive(Debug, Clone)] 12 | pub enum AnyStr<'a> { 13 | /// An owned String. 14 | #[cfg(feature = "alloc")] 15 | Owned(String), 16 | /// A borrowed string slice. 17 | Borrowed(&'a str), 18 | } 19 | 20 | impl<'a> AnyStr<'a> { 21 | /// Returns this string as a `str` reference. 22 | /// 23 | /// This function in general doesn't need to be called, as `AnyStr` 24 | /// implements `AsRef`, `Borrow`, and `Deref`. This 25 | /// allows it to act as if it were a `&str` in most situations. 26 | #[inline] 27 | #[must_use] 28 | pub fn as_str(&self) -> &str { 29 | match self { 30 | #[cfg(feature = "alloc")] 31 | Self::Owned(str) => str, 32 | Self::Borrowed(str) => str, 33 | } 34 | } 35 | } 36 | 37 | impl<'a> AsRef for AnyStr<'a> { 38 | #[inline] 39 | fn as_ref(&self) -> &str { 40 | self.as_str() 41 | } 42 | } 43 | 44 | impl<'a> Borrow for AnyStr<'a> { 45 | #[inline] 46 | fn borrow(&self) -> &str { 47 | self.as_ref() 48 | } 49 | } 50 | 51 | impl<'a> Eq for AnyStr<'a> {} 52 | 53 | impl<'a, 'b> PartialEq> for AnyStr<'a> { 54 | #[inline] 55 | fn eq(&self, other: &AnyStr<'b>) -> bool { 56 | self.as_ref() == other.as_ref() 57 | } 58 | } 59 | 60 | impl<'a, 'b> PartialEq<&'b str> for AnyStr<'a> { 61 | #[inline] 62 | fn eq(&self, other: &&'b str) -> bool { 63 | self == *other 64 | } 65 | } 66 | 67 | impl<'a> PartialEq for AnyStr<'a> { 68 | #[inline] 69 | fn eq(&self, other: &str) -> bool { 70 | self.as_ref() == other 71 | } 72 | } 73 | 74 | impl<'a, 'b> PartialOrd> for AnyStr<'a> { 75 | #[inline] 76 | fn partial_cmp(&self, other: &AnyStr<'b>) -> Option { 77 | self.partial_cmp(other.as_ref()) 78 | } 79 | } 80 | 81 | impl<'a, 'b> PartialOrd<&'b str> for AnyStr<'a> { 82 | #[inline] 83 | fn partial_cmp(&self, other: &&'b str) -> Option { 84 | self.partial_cmp(*other) 85 | } 86 | } 87 | impl<'a> PartialOrd for AnyStr<'a> { 88 | #[inline] 89 | fn partial_cmp(&self, other: &str) -> Option { 90 | self.as_ref().partial_cmp(other) 91 | } 92 | } 93 | 94 | impl<'a> Deref for AnyStr<'a> { 95 | type Target = str; 96 | 97 | #[inline] 98 | fn deref(&self) -> &Self::Target { 99 | self.as_ref() 100 | } 101 | } 102 | 103 | impl<'a> Hash for AnyStr<'a> { 104 | #[inline] 105 | fn hash(&self, state: &mut H) { 106 | self.as_ref().hash(state); 107 | } 108 | } 109 | 110 | impl<'a> From<&'a str> for AnyStr<'a> { 111 | #[inline] 112 | fn from(value: &'a str) -> Self { 113 | Self::Borrowed(value) 114 | } 115 | } 116 | 117 | #[cfg(feature = "alloc")] 118 | impl<'a> From for AnyStr<'a> { 119 | #[inline] 120 | fn from(value: String) -> Self { 121 | Self::Owned(value) 122 | } 123 | } 124 | 125 | #[test] 126 | #[cfg(feature = "std")] 127 | fn hash() { 128 | let mut set = std::collections::HashSet::new(); 129 | set.insert(AnyStr::from(String::from("hello"))); 130 | assert!(set.contains(&AnyStr::from("hello"))); 131 | assert!(set.contains("hello")); 132 | } 133 | 134 | #[test] 135 | fn ord() { 136 | assert!(AnyStr::Borrowed("a") < "b"); 137 | assert!(AnyStr::Borrowed("a") < AnyStr::Borrowed("b")); 138 | } 139 | -------------------------------------------------------------------------------- /src/doc.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "alloc")] 2 | use alloc::vec::Vec; 3 | use core::iter::Cloned; 4 | use core::marker::PhantomData; 5 | use core::slice; 6 | 7 | use crate::parser::{JsonKind, ParseConfig, ParseDelegate, Parser}; 8 | #[cfg(feature = "alloc")] 9 | use crate::{value::Entry, Object, Value}; 10 | use crate::{Error, ErrorKind, JsonNumber, JsonString}; 11 | 12 | /// A parsed JSON payload. 13 | /// 14 | /// This type is a read-only view into the JSON payload. 15 | /// 16 | /// This structure is faster to parse than [`Value`], but it is more work to 17 | /// interact with because the entire payload is stored in a single list 18 | /// internally. 19 | /// 20 | /// The list of [`Node`]s is sequentially ordered by the order in which they 21 | /// appear in the document. This means that the first [`Node`] tells us what the 22 | /// root type of the document is. 23 | /// 24 | /// The nodes [`Node::Null`], [`Node::Boolean`], [`Node::String`], and 25 | /// [`Node::Number`] all directly represent a [`Value`] with the same name. 26 | /// 27 | /// [`Node::Object`] contains a length field, which lets us know how many 28 | /// key-value pairs will appear after the object's node. Object keys are 29 | /// guaranteed to be [`Node::String`]s, but object values can be any [`Node`] 30 | /// variant. This means care must be taken to handle nested structures. 31 | /// 32 | /// [`Node::Array`] also contains a length field, which lets us know how many 33 | /// values follow the array's node. Because array values can be any type, care 34 | /// must be taken to handle nested structures correctly. 35 | /// 36 | /// [`DocumentIter`] has multiple methods to help efficiently deal with nested 37 | /// data types: 38 | /// 39 | /// - [`skip_next_value()`](DocumentIter::skip_next_value): Skips over the next 40 | /// value, taking care to handle nested structures properly. 41 | /// - [`next_value()`](DocumentIter::next_value): Returns a [`Value`] from the 42 | /// iterator. 43 | #[derive(Debug, Eq, PartialEq)] 44 | pub struct GenericDocument<'a, Backing> { 45 | nodes: Nodes<'a, Backing>, 46 | } 47 | 48 | impl<'a, Backing> GenericDocument<'a, Backing> 49 | where 50 | Backing: NodeCollection<'a>, 51 | { 52 | /// Parses a JSON payload from `source`. 53 | /// 54 | /// This function verifies that `json` is valid UTF-8 while parsing the 55 | /// JSON. 56 | pub fn from_json_bytes(source: &'a [u8]) -> Result 57 | where 58 | Backing: Default, 59 | { 60 | let mut nodes = Nodes::default(); 61 | Parser::parse_json_bytes(source, &mut nodes).map_err(Error::into_infallable)?; 62 | Ok(Self { nodes }) 63 | } 64 | 65 | /// Parses a JSON payload from `source`, with the settings from `config`. 66 | /// 67 | /// This function verifies that `json` is valid UTF-8 while parsing the 68 | /// JSON. 69 | pub fn from_json_bytes_with_config(source: &'a [u8], config: ParseConfig) -> Result 70 | where 71 | Backing: Default, 72 | { 73 | let mut nodes = Nodes::default(); 74 | Parser::parse_json_bytes_with_config(source, config, &mut nodes) 75 | .map_err(Error::into_infallable)?; 76 | Ok(Self { nodes }) 77 | } 78 | 79 | /// Parses a JSON payload from `source`. 80 | /// 81 | /// Because the `str` type guarantees that `json` is valid UTF-8, no 82 | /// additional unicode checks are performed on unescaped unicode sequences. 83 | pub fn from_json(source: &'a str) -> Result 84 | where 85 | Backing: Default, 86 | { 87 | let mut nodes = Nodes::default(); 88 | Parser::parse_json(source, &mut nodes).map_err(Error::into_infallable)?; 89 | Ok(Self { nodes }) 90 | } 91 | 92 | /// Parses a JSON payload from `source`, with the settings from `config`. 93 | /// 94 | /// Because the `str` type guarantees that `json` is valid UTF-8, no 95 | /// additional unicode checks are performed on unescaped unicode sequences. 96 | pub fn from_json_with_config(source: &'a str, config: ParseConfig) -> Result 97 | where 98 | Backing: Default, 99 | { 100 | let mut nodes = Nodes::default(); 101 | Parser::parse_json_with_config(source, config, &mut nodes) 102 | .map_err(Error::into_infallable)?; 103 | Ok(Self { nodes }) 104 | } 105 | 106 | /// Returns an iterator over the nodes in this document. 107 | #[must_use] 108 | pub fn iter(&self) -> DocumentIter<'_, 'a> { 109 | self.into_iter() 110 | } 111 | } 112 | 113 | #[cfg(feature = "alloc")] 114 | impl<'a, Backing> From> for Value<'a> 115 | where 116 | Backing: NodeCollection<'a>, 117 | { 118 | fn from(doc: GenericDocument<'a, Backing>) -> Self { 119 | let mut nodes = doc.nodes.collection.into_iter(); 120 | let root = nodes.next().expect("empty document is invalid"); 121 | hydrate_value_from_node(root, &mut nodes) 122 | } 123 | } 124 | 125 | #[cfg(feature = "alloc")] 126 | fn hydrate_value_from_node<'a, I>(node: Node<'a>, remaining_nodes: &mut I) -> Value<'a> 127 | where 128 | I: Iterator>, 129 | { 130 | match node { 131 | Node::Null => Value::Null, 132 | Node::Boolean(value) => Value::Boolean(value), 133 | Node::String(value) => Value::String(value), 134 | Node::Number(number) => Value::Number(number), 135 | Node::Object { length: len } => { 136 | let mut obj = Object::with_capacity(len); 137 | for _ in 0..len { 138 | let node = remaining_nodes.next().expect("obbject missing value"); 139 | let Node::String(key) = node else { unreachable!("object key must be string") }; 140 | let node = remaining_nodes.next().expect("object missing value"); 141 | obj.push(Entry { 142 | key, 143 | value: hydrate_value_from_node(node, remaining_nodes), 144 | }); 145 | } 146 | Value::Object(obj) 147 | } 148 | Node::Array { length: len } => { 149 | let mut values = Vec::with_capacity(len); 150 | for _ in 0..len { 151 | let node = remaining_nodes.next().expect("array missing value"); 152 | values.push(hydrate_value_from_node(node, remaining_nodes)); 153 | } 154 | Value::Array(values) 155 | } 156 | } 157 | } 158 | 159 | impl<'doc, 'a, Backing> IntoIterator for &'doc GenericDocument<'a, Backing> 160 | where 161 | Backing: NodeCollection<'a>, 162 | { 163 | type IntoIter = DocumentIter<'doc, 'a>; 164 | type Item = Node<'a>; 165 | 166 | fn into_iter(self) -> Self::IntoIter { 167 | DocumentIter { 168 | nodes: self.nodes.collection.as_ref().iter().cloned(), 169 | } 170 | } 171 | } 172 | 173 | /// A single value in a [`Document`]. 174 | #[derive(Debug, Eq, PartialEq, Clone)] 175 | pub enum Node<'a> { 176 | /// A null value. 177 | Null, 178 | /// A boolean value. 179 | Boolean(bool), 180 | /// A string value. 181 | String(JsonString<'a>), 182 | /// A numerical value. 183 | Number(JsonNumber<'a>), 184 | /// An object value with `len` key-value pairs following it. 185 | Object { 186 | /// The number of key-value pairs that this object contains. 187 | length: usize, 188 | }, 189 | /// An array with `len` values following it. 190 | Array { 191 | /// The number of values that this array contains. 192 | length: usize, 193 | }, 194 | } 195 | 196 | #[derive(Default, Debug, Eq, PartialEq)] 197 | struct Nodes<'a, Backing> { 198 | collection: Backing, 199 | _phantom: PhantomData<&'a ()>, 200 | } 201 | 202 | impl<'a, Backing> Nodes<'a, Backing> 203 | where 204 | Backing: NodeCollection<'a>, 205 | { 206 | fn push_node(&mut self, node: Node<'a>) -> Result { 207 | let index = self.collection.as_ref().len(); 208 | self.collection.push(node)?; 209 | Ok(index) 210 | } 211 | 212 | pub fn push_null(&mut self) -> Result { 213 | self.push_node(Node::Null) 214 | } 215 | 216 | pub fn push_bool(&mut self, boolean: bool) -> Result { 217 | self.push_node(Node::Boolean(boolean)) 218 | } 219 | 220 | pub fn push_string(&mut self, string: JsonString<'a>) -> Result { 221 | self.push_node(Node::String(string)) 222 | } 223 | 224 | pub fn push_number(&mut self, number: JsonNumber<'a>) -> Result { 225 | self.push_node(Node::Number(number)) 226 | } 227 | 228 | pub fn push_object(&mut self) -> Result { 229 | self.push_node(Node::Object { length: 0 }) 230 | } 231 | 232 | pub fn push_array(&mut self) -> Result { 233 | self.push_node(Node::Array { length: 0 }) 234 | } 235 | 236 | pub fn extend_object(&mut self, index: usize) { 237 | let Node::Object { length: len } = &mut self.collection.as_mut()[index] else { unreachable!("extended wrong type") }; 238 | *len += 1; 239 | } 240 | 241 | pub fn extend_array(&mut self, index: usize) { 242 | let Node::Array { length: len } = &mut self.collection.as_mut()[index] else { unreachable!("extended wrong type") }; 243 | *len += 1; 244 | } 245 | } 246 | 247 | impl<'a, 'b, Backing> ParseDelegate<'a> for &'b mut Nodes<'a, Backing> 248 | where 249 | Backing: NodeCollection<'a>, 250 | { 251 | type Array = usize; 252 | type Error = ErrorKind; 253 | type Key = (); 254 | type Object = usize; 255 | type Value = usize; 256 | 257 | #[inline] 258 | fn null(&mut self) -> Result { 259 | self.push_null() 260 | } 261 | 262 | #[inline] 263 | fn boolean(&mut self, value: bool) -> Result { 264 | self.push_bool(value) 265 | } 266 | 267 | #[inline] 268 | fn number(&mut self, value: JsonNumber<'a>) -> Result { 269 | self.push_number(value) 270 | } 271 | 272 | #[inline] 273 | fn string(&mut self, value: JsonString<'a>) -> Result { 274 | self.push_string(value) 275 | } 276 | 277 | #[inline] 278 | fn begin_object(&mut self) -> Result { 279 | self.push_object() 280 | } 281 | 282 | #[inline] 283 | fn object_key( 284 | &mut self, 285 | object: &mut Self::Object, 286 | key: JsonString<'a>, 287 | ) -> Result { 288 | self.extend_object(*object); 289 | self.push_string(key)?; 290 | Ok(()) 291 | } 292 | 293 | #[inline] 294 | fn object_value( 295 | &mut self, 296 | _object: &mut Self::Object, 297 | _key: Self::Key, 298 | _value: Self::Value, 299 | ) -> Result<(), Self::Error> { 300 | Ok(()) 301 | } 302 | 303 | #[inline] 304 | fn object_is_empty(&self, object: &Self::Object) -> bool { 305 | let Node::Object { length: len } = &self.collection.as_ref()[*object] else { unreachable!("invalid object") }; 306 | *len == 0 307 | } 308 | 309 | #[inline] 310 | fn end_object(&mut self, object: Self::Object) -> Result { 311 | Ok(object) 312 | } 313 | 314 | #[inline] 315 | fn begin_array(&mut self) -> Result { 316 | self.push_array() 317 | } 318 | 319 | #[inline] 320 | fn array_value( 321 | &mut self, 322 | array: &mut Self::Array, 323 | _value: Self::Value, 324 | ) -> Result<(), Self::Error> { 325 | self.extend_array(*array); 326 | Ok(()) 327 | } 328 | 329 | #[inline] 330 | fn array_is_empty(&self, array: &Self::Array) -> bool { 331 | let Node::Array { length: len } = &self.collection.as_ref()[*array] else { unreachable!("invalid array") }; 332 | *len == 0 333 | } 334 | 335 | #[inline] 336 | fn end_array(&mut self, array: Self::Array) -> Result { 337 | Ok(array) 338 | } 339 | 340 | #[inline] 341 | fn kind_of(&self, value: &Self::Value) -> JsonKind { 342 | match &self.collection.as_ref()[*value] { 343 | Node::Null => JsonKind::Null, 344 | Node::Boolean(_) => JsonKind::Boolean, 345 | Node::String(_) => JsonKind::String, 346 | Node::Number(_) => JsonKind::Number, 347 | Node::Object { .. } => JsonKind::Object, 348 | Node::Array { .. } => JsonKind::Array, 349 | } 350 | } 351 | } 352 | 353 | /// An iterator over the [`Node`]s in a [`Document`]. 354 | #[derive(Debug, Clone)] 355 | pub struct DocumentIter<'doc, 'a> { 356 | nodes: Cloned>>, 357 | } 358 | 359 | impl<'doc, 'a> DocumentIter<'doc, 'a> { 360 | /// Reads a [`Value`] from the iterator, if any nodes remain. 361 | /// 362 | /// This function automatically reads nested objects and arrays. 363 | /// 364 | /// ```rust 365 | /// use justjson::doc::{Document, Node}; 366 | /// use justjson::Value; 367 | /// 368 | /// let doc = Document::from_json( 369 | /// r#"{ 370 | /// "a": [1, 2, 3, 4] 371 | /// }"#, 372 | /// ) 373 | /// .unwrap(); 374 | /// 375 | /// let mut nodes = doc.iter(); 376 | /// assert_eq!(nodes.next(), Some(Node::Object { length: 1 })); 377 | /// let Node::String(key) = nodes.next().unwrap() else { unreachable!() }; 378 | /// assert_eq!(key, "a"); 379 | /// let Value::Array(array) = nodes.next_value().unwrap() else { unreachable!() }; 380 | /// assert_eq!(array.len(), 4); 381 | /// assert!(nodes.next().is_none()); 382 | /// ``` 383 | #[cfg(feature = "alloc")] 384 | pub fn next_value(&mut self) -> Option> { 385 | let node = self.nodes.next()?; 386 | 387 | Some(hydrate_value_from_node(node, &mut self.nodes)) 388 | } 389 | 390 | /// Skips a [`Value`], including any nested values. 391 | pub fn skip_next_value(&mut self) { 392 | if let Some(node) = self.nodes.next() { 393 | match node { 394 | Node::Null | Node::Boolean(_) | Node::String(_) | Node::Number(_) => {} 395 | Node::Object { length: len } => { 396 | for _ in 0..len { 397 | // Skip the key 398 | self.skip_next_value(); 399 | // Skip the value 400 | self.skip_next_value(); 401 | } 402 | } 403 | Node::Array { length: len } => { 404 | for _ in 0..len { 405 | // Skip the value 406 | self.skip_next_value(); 407 | } 408 | } 409 | } 410 | } 411 | } 412 | } 413 | 414 | impl<'doc, 'a> Iterator for DocumentIter<'doc, 'a> { 415 | type Item = Node<'a>; 416 | 417 | #[inline] 418 | fn next(&mut self) -> Option { 419 | self.nodes.next() 420 | } 421 | } 422 | 423 | #[test] 424 | #[cfg(feature = "alloc")] 425 | fn document_iteration() { 426 | let source = r#"{"a":1,"b":true,"c":"hello","d":[null],"e":{}}"#; 427 | let doc = Document::from_json(source).unwrap(); 428 | assert_eq!( 429 | doc.iter().collect::>(), 430 | alloc::vec![ 431 | Node::Object { length: 5 }, 432 | Node::String(JsonString::from_json("\"a\"").unwrap()), 433 | Node::Number(JsonNumber::from_json("1").unwrap()), 434 | Node::String(JsonString::from_json("\"b\"").unwrap()), 435 | Node::Boolean(true), 436 | Node::String(JsonString::from_json("\"c\"").unwrap()), 437 | Node::String(JsonString::from_json("\"hello\"").unwrap()), 438 | Node::String(JsonString::from_json("\"d\"").unwrap()), 439 | Node::Array { length: 1 }, 440 | Node::Null, 441 | Node::String(JsonString::from_json("\"e\"").unwrap()), 442 | Node::Object { length: 0 }, 443 | ] 444 | ); 445 | let value = doc.iter().next_value().unwrap(); 446 | assert_eq!(value, Value::from_json(source).unwrap()); 447 | 448 | // Test skipping 449 | let mut iter = doc.iter(); 450 | iter.skip_next_value(); 451 | assert!(iter.next().is_none()); 452 | } 453 | 454 | /// A collection for use with [`GenericDocument`]. 455 | pub trait NodeCollection<'a>: 456 | AsRef<[Node<'a>]> + AsMut<[Node<'a>]> + IntoIterator> 457 | { 458 | /// Push `node` to the end of the collection. 459 | fn push(&mut self, node: Node<'a>) -> Result<(), ErrorKind>; 460 | } 461 | 462 | #[cfg(feature = "alloc")] 463 | impl<'a> NodeCollection<'a> for Vec> { 464 | #[inline] 465 | fn push(&mut self, node: Node<'a>) -> Result<(), ErrorKind> { 466 | self.push(node); 467 | Ok(()) 468 | } 469 | } 470 | 471 | #[cfg(feature = "heapless")] 472 | impl<'a, const N: usize> NodeCollection<'a> for heapless::Vec, N> { 473 | #[inline] 474 | fn push(&mut self, node: Node<'a>) -> Result<(), ErrorKind> { 475 | self.push(node).map_err(|_| ErrorKind::PaylodTooLarge) 476 | } 477 | } 478 | 479 | /// A convenience alias for a [`GenericDocument`] that uses a `Vec` from 480 | /// `std`/`alloc`. 481 | #[cfg(feature = "alloc")] 482 | pub type Document<'a> = GenericDocument<'a, Vec>>; 483 | 484 | /// A convenience alias for a [`GenericDocument`] that uses a `heapless::Vec`. 485 | #[cfg(feature = "heapless")] 486 | pub type HeaplessDocument<'a, const N: usize> = GenericDocument<'a, heapless::Vec, N>>; 487 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![doc = include_str!("../README.md")] 2 | #![warn( 3 | clippy::cargo, 4 | missing_docs, 5 | clippy::pedantic, 6 | future_incompatible, 7 | rust_2018_idioms 8 | )] 9 | #![allow( 10 | clippy::option_if_let_else, 11 | clippy::module_name_repetitions, 12 | clippy::missing_errors_doc 13 | )] 14 | #![deny(unsafe_code)] 15 | #![no_std] 16 | #![cfg_attr(any(docsrs, feature = "nightly"), feature(doc_auto_cfg))] 17 | 18 | #[cfg(any(feature = "std", test))] 19 | extern crate std; 20 | 21 | #[cfg(feature = "alloc")] 22 | extern crate alloc; 23 | 24 | pub use crate::anystr::AnyStr; 25 | pub use crate::error::{Error, ErrorKind}; 26 | pub use crate::number::JsonNumber; 27 | pub use crate::string::{JsonString, JsonStringInfo}; 28 | #[cfg(feature = "alloc")] 29 | pub use crate::value::{Entry, Object, Value}; 30 | 31 | mod anystr; 32 | /// A JSON DOM representation with minimal processing. 33 | pub mod doc; 34 | mod error; 35 | mod number; 36 | /// A low-level event-driven JSON parser. 37 | pub mod parser; 38 | mod string; 39 | #[cfg(all(test, feature = "alloc"))] 40 | mod tests; 41 | #[cfg(feature = "alloc")] 42 | mod value; 43 | -------------------------------------------------------------------------------- /src/number.rs: -------------------------------------------------------------------------------- 1 | use core::str::FromStr; 2 | 3 | use crate::anystr::AnyStr; 4 | use crate::parser::{ParseDelegate, Parser}; 5 | use crate::{Error, ErrorKind}; 6 | 7 | /// A JSON-encoded number. 8 | #[derive(Debug, Eq, PartialEq, Clone)] 9 | pub struct JsonNumber<'a> { 10 | /// The JSON source for this number. 11 | pub(crate) source: AnyStr<'a>, 12 | } 13 | 14 | impl<'a> JsonNumber<'a> { 15 | /// Parses `json`, expecting a single number value. 16 | /// 17 | /// # Errors 18 | /// 19 | /// Returns [`ErrorKind::ExpectedString`] if a non-string value is 20 | /// encountered. 21 | pub fn from_json(json: &'a str) -> Result { 22 | Parser::parse_json(json, NumberParser).map_err(Error::into_infallable) 23 | } 24 | 25 | /// Returns the JSON-encoded representation of this number. 26 | #[must_use] 27 | pub fn source(&self) -> &str { 28 | self.source.as_ref() 29 | } 30 | 31 | /// Parses the contained value as an [`f32`], if possible. 32 | /// 33 | /// The JSON parser only validates that the number takes a correct form. If 34 | /// a number cannot be parsed by the underlying routine due to having too 35 | /// many digits, it this function can return None. 36 | #[must_use] 37 | pub fn as_f32(&self) -> Option { 38 | self.parse().ok() 39 | } 40 | 41 | /// Parses the contained value as an [`f64`], if possible. 42 | /// 43 | /// The JSON parser only validates that the number takes a correct form. If 44 | /// a number cannot be parsed by the underlying routine due to having too 45 | /// many digits, it this function can return None. 46 | #[must_use] 47 | pub fn as_f64(&self) -> Option { 48 | self.parse().ok() 49 | } 50 | 51 | /// Parses the contained value. 52 | pub fn parse(&self) -> Result { 53 | self.source().parse() 54 | } 55 | } 56 | 57 | macro_rules! impl_as_number { 58 | ($name:ident, $type:ident) => { 59 | impl JsonNumber<'_> { 60 | /// Parses the contained value as an 61 | #[doc = concat!("[`", stringify!($type), "`]")] 62 | /// if possible. 63 | /// 64 | /// If the source number is a floating point number or has a negative sign, 65 | /// this will always return None. 66 | #[must_use] 67 | pub fn $name(&self) -> Option<$type> { 68 | self.parse().ok() 69 | } 70 | } 71 | }; 72 | } 73 | 74 | impl_as_number!(as_u8, u8); 75 | impl_as_number!(as_u16, u16); 76 | impl_as_number!(as_u32, u32); 77 | impl_as_number!(as_u64, u64); 78 | impl_as_number!(as_u128, u128); 79 | impl_as_number!(as_usize, usize); 80 | impl_as_number!(as_i8, i8); 81 | impl_as_number!(as_i16, i16); 82 | impl_as_number!(as_i32, i32); 83 | impl_as_number!(as_i64, i64); 84 | impl_as_number!(as_i128, i128); 85 | impl_as_number!(as_isize, isize); 86 | 87 | struct NumberParser; 88 | 89 | impl<'a> ParseDelegate<'a> for NumberParser { 90 | type Array = (); 91 | type Error = ErrorKind; 92 | type Key = (); 93 | type Object = (); 94 | type Value = JsonNumber<'a>; 95 | 96 | fn null(&mut self) -> Result { 97 | Err(ErrorKind::ExpectedNumber) 98 | } 99 | 100 | fn boolean(&mut self, _value: bool) -> Result { 101 | Err(ErrorKind::ExpectedNumber) 102 | } 103 | 104 | fn number(&mut self, value: JsonNumber<'a>) -> Result { 105 | Ok(value) 106 | } 107 | 108 | fn string(&mut self, _value: crate::JsonString<'a>) -> Result { 109 | Err(ErrorKind::ExpectedNumber) 110 | } 111 | 112 | fn begin_object(&mut self) -> Result { 113 | Err(ErrorKind::ExpectedNumber) 114 | } 115 | 116 | fn object_key( 117 | &mut self, 118 | _object: &mut Self::Object, 119 | _key: crate::JsonString<'a>, 120 | ) -> Result { 121 | unreachable!("error returned from begin_object") 122 | } 123 | 124 | fn object_value( 125 | &mut self, 126 | _object: &mut Self::Object, 127 | _key: Self::Key, 128 | _value: Self::Value, 129 | ) -> Result<(), Self::Error> { 130 | unreachable!("error returned from begin_object") 131 | } 132 | 133 | fn object_is_empty(&self, _object: &Self::Object) -> bool { 134 | unreachable!("error returned from begin_object") 135 | } 136 | 137 | fn end_object(&mut self, _object: Self::Object) -> Result { 138 | unreachable!("error returned from begin_object") 139 | } 140 | 141 | fn begin_array(&mut self) -> Result { 142 | Err(ErrorKind::ExpectedNumber) 143 | } 144 | 145 | fn array_value( 146 | &mut self, 147 | _array: &mut Self::Array, 148 | _value: Self::Value, 149 | ) -> Result<(), Self::Error> { 150 | unreachable!("error returned from array_value") 151 | } 152 | 153 | fn array_is_empty(&self, _array: &Self::Array) -> bool { 154 | unreachable!("error returned from array_value") 155 | } 156 | 157 | fn end_array(&mut self, _array: Self::Array) -> Result { 158 | unreachable!("error returned from array_value") 159 | } 160 | 161 | fn kind_of(&self, _value: &Self::Value) -> crate::parser::JsonKind { 162 | unreachable!("allow_all_types_at_root is always true") 163 | } 164 | } 165 | 166 | #[test] 167 | #[cfg(feature = "alloc")] 168 | fn json_number_from_json() { 169 | assert_eq!( 170 | JsonNumber::from_json("1").unwrap(), 171 | JsonNumber { 172 | source: AnyStr::Borrowed("1") 173 | } 174 | ); 175 | 176 | let expected_number = JsonNumber::from_json("true") 177 | .expect_err("shouldn't allow non-numbers") 178 | .kind; 179 | assert!(matches!(expected_number, ErrorKind::ExpectedNumber)); 180 | } 181 | 182 | #[test] 183 | #[cfg(feature = "alloc")] 184 | fn json_number_conversions() { 185 | let one = JsonNumber::from_json("1").unwrap(); 186 | assert_eq!(one.as_i64().unwrap(), 1); 187 | assert_eq!(one.as_u64().unwrap(), 1); 188 | assert!((one.as_f64().unwrap() - 1.0).abs() < f64::EPSILON); 189 | } 190 | 191 | #[test] 192 | fn from_json_bad_types() { 193 | assert_eq!( 194 | JsonNumber::from_json("\"\"").unwrap_err().kind, 195 | ErrorKind::ExpectedNumber 196 | ); 197 | assert_eq!( 198 | JsonNumber::from_json("null").unwrap_err().kind, 199 | ErrorKind::ExpectedNumber 200 | ); 201 | assert_eq!( 202 | JsonNumber::from_json("true").unwrap_err().kind, 203 | ErrorKind::ExpectedNumber 204 | ); 205 | assert_eq!( 206 | JsonNumber::from_json("[]").unwrap_err().kind, 207 | ErrorKind::ExpectedNumber 208 | ); 209 | assert_eq!( 210 | JsonNumber::from_json("{}").unwrap_err().kind, 211 | ErrorKind::ExpectedNumber 212 | ); 213 | } 214 | 215 | #[test] 216 | #[cfg(feature = "alloc")] 217 | fn as_es() { 218 | macro_rules! test_as { 219 | ($as:ident) => { 220 | assert_eq!(JsonNumber::from_json("1").unwrap().$as(), Some(1)); 221 | }; 222 | } 223 | 224 | test_as!(as_i8); 225 | test_as!(as_i16); 226 | test_as!(as_i32); 227 | test_as!(as_i64); 228 | test_as!(as_i128); 229 | test_as!(as_isize); 230 | test_as!(as_u8); 231 | test_as!(as_u16); 232 | test_as!(as_u32); 233 | test_as!(as_u64); 234 | test_as!(as_u128); 235 | test_as!(as_usize); 236 | 237 | assert!(JsonNumber::from_json("0").unwrap().as_f32().unwrap().abs() < f32::EPSILON); 238 | assert!(JsonNumber::from_json("0").unwrap().as_f64().unwrap().abs() < f64::EPSILON); 239 | } 240 | -------------------------------------------------------------------------------- /src/tests.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "alloc")] 2 | use alloc::{ 3 | string::{String, ToString}, 4 | vec, 5 | }; 6 | use core::fmt::Write; 7 | use std::println; 8 | 9 | use crate::anystr::AnyStr; 10 | use crate::doc::Document; 11 | use crate::parser::{ParseConfig, ParseDelegate, Parser}; 12 | use crate::string::StringContents; 13 | use crate::value::ValueParser; 14 | use crate::{Error, ErrorKind, JsonNumber, JsonString, JsonStringInfo, Object, Value}; 15 | 16 | #[track_caller] 17 | fn test_json_parse(source: &[u8], value: &Value<'_>) { 18 | println!("Testing slice {}", std::str::from_utf8(source).unwrap()); 19 | 20 | let parsed_value = Value::from_json_bytes(source).unwrap(); 21 | assert_eq!(&parsed_value, value); 22 | 23 | let doc = Document::from_json_bytes(source).unwrap(); 24 | assert_eq!(Value::from(doc), parsed_value); 25 | } 26 | 27 | #[test] 28 | fn keywords() { 29 | test_json_parse(b"true", &Value::from(true)); 30 | test_json_parse(b"false", &Value::from(false)); 31 | test_json_parse(b"null", &Value::Null); 32 | } 33 | 34 | #[test] 35 | fn empty_array() { 36 | test_json_parse(b"[]", &Value::Array(vec![])); 37 | } 38 | 39 | #[test] 40 | fn one_element_array() { 41 | test_json_parse(b"[true]", &Value::Array(vec![Value::from(true)])); 42 | } 43 | 44 | #[test] 45 | fn two_element_array() { 46 | test_json_parse( 47 | b"[true,false]", 48 | &Value::Array(vec![Value::from(true), Value::from(false)]), 49 | ); 50 | } 51 | 52 | #[test] 53 | fn spaced_out_array() { 54 | test_json_parse( 55 | b" [ true , false ] ", 56 | &Value::Array(vec![Value::from(true), Value::from(false)]), 57 | ); 58 | } 59 | 60 | #[test] 61 | fn whitespace() { 62 | test_json_parse(b" \t\n\rnull", &Value::Null); 63 | } 64 | 65 | #[test] 66 | fn basic_string() { 67 | test_json_parse( 68 | br#""hello""#, 69 | &Value::from(JsonString { 70 | source: StringContents::Json(AnyStr::Borrowed("hello")), 71 | info: JsonStringInfo::new(false, 5), 72 | }), 73 | ); 74 | test_json_parse( 75 | br#""""#, 76 | &Value::from(JsonString { 77 | source: StringContents::Json(AnyStr::Borrowed("")), 78 | info: JsonStringInfo::new(false, 0), 79 | }), 80 | ); 81 | } 82 | 83 | #[test] 84 | fn escapey_string() { 85 | test_json_parse( 86 | br#""\"\\\/\b\f\n\r\t\u25eF""#, 87 | &Value::from(JsonString { 88 | source: StringContents::Json(AnyStr::Borrowed(r#"\"\\\/\b\f\n\r\t\u25eF"#)), 89 | info: JsonStringInfo::new(true, 11), 90 | }), 91 | ); 92 | } 93 | 94 | #[test] 95 | fn surrogate_pair() { 96 | test_json_parse( 97 | br#""\ud83d\ude39\ud83d\udc8d""#, 98 | &Value::from(JsonString::from_json("\"\u{1f639}\u{1f48d}\"").unwrap()), 99 | ); 100 | assert_eq!( 101 | JsonString::from_json(r#""\ud83d\ude39\ud83d\udc8d""#,).unwrap(), 102 | "\u{1f639}\u{1f48d}" 103 | ); 104 | } 105 | 106 | #[test] 107 | fn empty_object() { 108 | test_json_parse(b"{}", &Value::Object(Object::new())); 109 | } 110 | 111 | #[test] 112 | fn one_mapping() { 113 | test_json_parse( 114 | br#"{"hello":true}"#, 115 | &Value::Object(Object::from_iter([( 116 | JsonString { 117 | source: StringContents::Json(AnyStr::Borrowed("hello")), 118 | info: JsonStringInfo::new(false, 5), 119 | }, 120 | Value::from(true), 121 | )])), 122 | ); 123 | } 124 | 125 | #[test] 126 | fn two_mappings() { 127 | test_json_parse( 128 | br#"{"hello":true,"world":null}"#, 129 | &Value::Object(Object::from_iter([ 130 | ( 131 | JsonString { 132 | source: StringContents::Json(AnyStr::Borrowed("hello")), 133 | info: JsonStringInfo::new(false, 5), 134 | }, 135 | Value::from(true), 136 | ), 137 | ( 138 | JsonString { 139 | source: StringContents::Json(AnyStr::Borrowed("world")), 140 | info: JsonStringInfo::new(false, 5), 141 | }, 142 | Value::Null, 143 | ), 144 | ])), 145 | ); 146 | } 147 | 148 | #[test] 149 | fn spaced_out_object() { 150 | test_json_parse( 151 | br#" { "hello" : true , "world" : null } "#, 152 | &Value::Object(Object::from_iter([ 153 | ( 154 | JsonString::from_json("\"hello\"").unwrap(), 155 | Value::from(true), 156 | ), 157 | (JsonString::from_json("\"world\"").unwrap(), Value::Null), 158 | ])), 159 | ); 160 | } 161 | 162 | #[test] 163 | fn numbers() { 164 | for b in b'0'..=b'9' { 165 | test_json_parse( 166 | &[b], 167 | &Value::Number(JsonNumber { 168 | source: AnyStr::Borrowed(std::str::from_utf8(&[b]).unwrap()), 169 | }), 170 | ); 171 | } 172 | 173 | test_json_parse( 174 | b"-1", 175 | &Value::Number(JsonNumber { 176 | source: AnyStr::Borrowed("-1"), 177 | }), 178 | ); 179 | 180 | test_json_parse( 181 | b"-1.0", 182 | &Value::Number(JsonNumber { 183 | source: AnyStr::Borrowed("-1.0"), 184 | }), 185 | ); 186 | 187 | test_json_parse( 188 | b"-1.0e1", 189 | &Value::Number(JsonNumber { 190 | source: AnyStr::Borrowed("-1.0e1"), 191 | }), 192 | ); 193 | 194 | test_json_parse( 195 | b"-1.0E-1", 196 | &Value::Number(JsonNumber { 197 | source: AnyStr::Borrowed("-1.0E-1"), 198 | }), 199 | ); 200 | } 201 | 202 | #[test] 203 | fn object_of_everything() { 204 | test_json_parse( 205 | br#"{"a":1,"b":true,"c":"hello","d":[],"e":{}}"#, 206 | &Value::Object(Object::from_iter([ 207 | ( 208 | JsonString::from_json(r#""a""#).unwrap(), 209 | Value::Number(JsonNumber { 210 | source: AnyStr::Borrowed("1"), 211 | }), 212 | ), 213 | (JsonString::from_json(r#""b""#).unwrap(), Value::from(true)), 214 | ( 215 | JsonString::from_json(r#""c""#).unwrap(), 216 | Value::from(JsonString::from_json(r#""hello""#).unwrap()), 217 | ), 218 | ( 219 | JsonString::from_json(r#""d""#).unwrap(), 220 | Value::Array(vec![]), 221 | ), 222 | ( 223 | JsonString::from_json(r#""e""#).unwrap(), 224 | Value::Object(Object::new()), 225 | ), 226 | ])), 227 | ); 228 | } 229 | 230 | #[test] 231 | fn array_of_everything() { 232 | test_json_parse( 233 | br#"[1,true,"hello",[],{}]"#, 234 | &Value::Array(vec![ 235 | Value::Number(JsonNumber { 236 | source: AnyStr::Borrowed("1"), 237 | }), 238 | Value::from(true), 239 | Value::from(JsonString::from_json(r#""hello""#).unwrap()), 240 | Value::Array(vec![]), 241 | Value::Object(Object::new()), 242 | ]), 243 | ); 244 | } 245 | 246 | #[track_caller] 247 | fn expect_json_error(json: &str) -> Error { 248 | println!("Parsing {json}"); 249 | let err = Value::from_json(json).expect_err("parsing did not error"); 250 | println!("> {err:?}"); 251 | err 252 | } 253 | 254 | macro_rules! assert_json_error_kind_matches { 255 | ($json:expr, $offset:expr, $kind:expr) => {{ 256 | let err = expect_json_error($json); 257 | assert_eq!(err.kind(), &$kind); 258 | assert_eq!(err.offset(), $offset); 259 | }}; 260 | } 261 | 262 | #[test] 263 | fn object_errors() { 264 | assert_json_error_kind_matches!("{1:true}", 1, ErrorKind::ObjectKeysMustBeStrings); 265 | assert_json_error_kind_matches!(r#"{"a": true,}"#, 11, ErrorKind::IllegalTrailingComma); 266 | assert_json_error_kind_matches!(r#"{"a": true,:"#, 11, ErrorKind::ExpectedObjectKey); 267 | assert_json_error_kind_matches!(r#"{"a"}"#, 4, ErrorKind::ExpectedColon); 268 | assert_json_error_kind_matches!(r#"{"a""#, 4, ErrorKind::ExpectedColon); 269 | assert_json_error_kind_matches!(r#"{"a":}"#, 5, ErrorKind::Unexpected(b'}')); 270 | assert_json_error_kind_matches!(r#"{"a":1]"#, 6, ErrorKind::ExpectedCommaOrEndOfObject); 271 | assert_json_error_kind_matches!(r#"{"a": true,"#, 11, ErrorKind::UnclosedObject); 272 | } 273 | 274 | #[test] 275 | fn array_errors() { 276 | assert_json_error_kind_matches!("[1,]", 3, ErrorKind::IllegalTrailingComma); 277 | 278 | assert_json_error_kind_matches!("[1}", 2, ErrorKind::ExpectedCommaOrEndOfArray); 279 | 280 | assert_json_error_kind_matches!("[1,,}", 3, ErrorKind::Unexpected(b',')); 281 | 282 | assert_json_error_kind_matches!("[1,", 3, ErrorKind::UnclosedArray); 283 | 284 | assert_json_error_kind_matches!("[", 1, ErrorKind::UnclosedArray); 285 | } 286 | 287 | #[test] 288 | fn keyword_errors() { 289 | assert_json_error_kind_matches!("tru ", 3, ErrorKind::Unexpected(b' ')); 290 | assert_json_error_kind_matches!("tru", 3, ErrorKind::UnexpectedEof); 291 | } 292 | 293 | #[test] 294 | fn json_errors() { 295 | assert_json_error_kind_matches!("true true", 5, ErrorKind::TrailingNonWhitespace); 296 | 297 | assert_json_error_kind_matches!(",", 0, ErrorKind::Unexpected(b',')); 298 | 299 | assert_json_error_kind_matches!("#", 0, ErrorKind::Unexpected(b'#')); 300 | 301 | assert_json_error_kind_matches!("", 0, ErrorKind::UnexpectedEof); 302 | } 303 | 304 | #[test] 305 | fn string_errors() { 306 | assert_json_error_kind_matches!(r#"""#, 1, ErrorKind::UnclosedString); 307 | 308 | assert_json_error_kind_matches!("\"\0\"", 1, ErrorKind::Unexpected(b'\0')); 309 | 310 | assert_json_error_kind_matches!(r#""\?"#, 2, ErrorKind::InvalidEscape); 311 | 312 | assert_json_error_kind_matches!(r#""\udddd "#, 2, ErrorKind::Utf8); 313 | assert_json_error_kind_matches!(r#""\udda1 "#, 2, ErrorKind::Utf8); 314 | 315 | assert_json_error_kind_matches!(r#""\uG"#, 3, ErrorKind::InvalidHexadecimal); 316 | 317 | println!("Parsing invalid unicode"); 318 | let err = Value::from_json_bytes(b"\"\xdd\xdd\"").expect_err("parsing did not error"); 319 | println!("> {err:?}"); 320 | assert!(matches!(err.kind(), ErrorKind::Utf8)); 321 | } 322 | 323 | #[test] 324 | fn number_errors() { 325 | assert_json_error_kind_matches!("- ", 1, ErrorKind::ExpectedDigit); 326 | 327 | assert_json_error_kind_matches!("1. ", 2, ErrorKind::ExpectedDecimalDigit); 328 | 329 | assert_json_error_kind_matches!("1.0E ", 4, ErrorKind::ExpectedExponent); 330 | 331 | assert_json_error_kind_matches!("1.0E- ", 5, ErrorKind::ExpectedExponent); 332 | 333 | // Same battery of tests but with an eof instead 334 | assert_json_error_kind_matches!("-", 1, ErrorKind::ExpectedDigit); 335 | 336 | assert_json_error_kind_matches!("1.", 2, ErrorKind::ExpectedDecimalDigit); 337 | 338 | assert_json_error_kind_matches!("1.0E", 4, ErrorKind::ExpectedExponent); 339 | 340 | assert_json_error_kind_matches!("1.0E-", 5, ErrorKind::ExpectedExponent); 341 | } 342 | 343 | fn test_roundtrip_encoding(source: &str) { 344 | println!("Testing {source}"); 345 | let value = Value::from_json(source).unwrap(); 346 | assert_eq!(value.to_json(), source); 347 | } 348 | 349 | fn test_roundtrip_encoding_pretty_custom(source: &str, indentation: &str, line_ending: &str) { 350 | println!("Testing {source}"); 351 | let value = Value::from_json(source).unwrap(); 352 | assert_eq!( 353 | value.to_json_pretty_custom(indentation, line_ending), 354 | source 355 | ); 356 | } 357 | 358 | fn test_roundtrip_encoding_pretty(source: &str) { 359 | println!("Testing {source}"); 360 | let value = Value::from_json(source).unwrap(); 361 | assert_eq!(value.to_json_pretty(), source); 362 | } 363 | 364 | #[test] 365 | fn json_formatting() { 366 | test_roundtrip_encoding(r#"[1,true,"hello",[],{}]"#); 367 | test_roundtrip_encoding(r#"{"a":1,"b":true,"c":"hello","d":[],"e":{}}"#); 368 | test_roundtrip_encoding_pretty("[\n 1,\n true,\n \"hello\",\n [],\n {}\n]"); 369 | test_roundtrip_encoding_pretty( 370 | "{\n \"a\": 1,\n \"b\": true,\n \"c\": \"hello\",\n \"d\": [],\n \"e\": {}\n}", 371 | ); 372 | test_roundtrip_encoding_pretty_custom( 373 | "{\r\t\"a\": 1,\r\t\"b\": true,\r\t\"c\": \"hello\",\r\t\"d\": [],\r\t\"e\": {}\r}", 374 | "\t", 375 | "\r", 376 | ); 377 | test_roundtrip_encoding(r#""\u0000""#); 378 | } 379 | 380 | #[test] 381 | fn value_display() { 382 | let value = Value::from_json(r#"{"a":1,"b":true,"c":"hello","d":[],"e":{}}"#).unwrap(); 383 | assert_eq!( 384 | value.to_string(), 385 | r#"{"a":1,"b":true,"c":"hello","d":[],"e":{}}"# 386 | ); 387 | let mut pretty = String::new(); 388 | write!(&mut pretty, "{value:#}").unwrap(); 389 | assert_eq!( 390 | pretty, 391 | "{\n \"a\": 1,\n \"b\": true,\n \"c\": \"hello\",\n \"d\": [],\n \"e\": {}\n}" 392 | ); 393 | } 394 | 395 | struct ErroringDelegate { 396 | parser: ValueParser, 397 | error_on: ErrorOn, 398 | } 399 | impl ErroringDelegate { 400 | pub fn new(error_on: ErrorOn) -> Self { 401 | Self { 402 | error_on, 403 | parser: ValueParser, 404 | } 405 | } 406 | } 407 | 408 | #[derive(Debug, Eq, PartialEq)] 409 | enum ErrorOn { 410 | None, 411 | Null, 412 | Boolean(bool), 413 | Number(&'static str), 414 | String, 415 | BeginObject, 416 | ObjectKey, 417 | ObjectValue, 418 | EndObject, 419 | BeginArray, 420 | ArrayValue, 421 | EndArray, 422 | } 423 | 424 | #[derive(Eq, PartialEq, Debug)] 425 | struct MyError; 426 | 427 | impl<'a> ParseDelegate<'a> for ErroringDelegate { 428 | type Array = >::Array; 429 | type Error = MyError; 430 | type Key = JsonString<'a>; 431 | type Object = Object<'a>; 432 | type Value = Value<'a>; 433 | 434 | fn null(&mut self) -> Result { 435 | if matches!(self.error_on, ErrorOn::Null) { 436 | Err(MyError) 437 | } else { 438 | Ok(self.parser.null().unwrap()) 439 | } 440 | } 441 | 442 | fn boolean(&mut self, value: bool) -> Result { 443 | if self.error_on == ErrorOn::Boolean(value) { 444 | Err(MyError) 445 | } else { 446 | Ok(self.parser.boolean(value).unwrap()) 447 | } 448 | } 449 | 450 | fn number(&mut self, value: JsonNumber<'a>) -> Result { 451 | match &self.error_on { 452 | ErrorOn::Number(number) if value.source() == *number => Err(MyError), 453 | _ => Ok(self.parser.number(value).unwrap()), 454 | } 455 | } 456 | 457 | fn string(&mut self, value: JsonString<'a>) -> Result { 458 | if matches!(self.error_on, ErrorOn::String) { 459 | Err(MyError) 460 | } else { 461 | Ok(self.parser.string(value).unwrap()) 462 | } 463 | } 464 | 465 | fn begin_object(&mut self) -> Result { 466 | if matches!(self.error_on, ErrorOn::BeginObject) { 467 | Err(MyError) 468 | } else { 469 | Ok(self.parser.begin_object().unwrap()) 470 | } 471 | } 472 | 473 | fn object_key( 474 | &mut self, 475 | object: &mut Self::Object, 476 | key: JsonString<'a>, 477 | ) -> Result { 478 | if matches!(self.error_on, ErrorOn::ObjectKey) { 479 | Err(MyError) 480 | } else { 481 | Ok(self.parser.object_key(object, key).unwrap()) 482 | } 483 | } 484 | 485 | fn object_value( 486 | &mut self, 487 | object: &mut Self::Object, 488 | key: Self::Key, 489 | value: Self::Value, 490 | ) -> Result<(), Self::Error> { 491 | if matches!(self.error_on, ErrorOn::ObjectValue) { 492 | Err(MyError) 493 | } else { 494 | self.parser.object_value(object, key, value).unwrap(); 495 | Ok(()) 496 | } 497 | } 498 | 499 | fn object_is_empty(&self, object: &Self::Object) -> bool { 500 | self.parser.object_is_empty(object) 501 | } 502 | 503 | fn end_object(&mut self, object: Self::Object) -> Result { 504 | if matches!(self.error_on, ErrorOn::EndObject) { 505 | Err(MyError) 506 | } else { 507 | Ok(self.parser.end_object(object).unwrap()) 508 | } 509 | } 510 | 511 | fn begin_array(&mut self) -> Result { 512 | if matches!(self.error_on, ErrorOn::BeginArray) { 513 | Err(MyError) 514 | } else { 515 | Ok(self.parser.begin_array().unwrap()) 516 | } 517 | } 518 | 519 | fn array_value( 520 | &mut self, 521 | array: &mut Self::Array, 522 | value: Self::Value, 523 | ) -> Result<(), Self::Error> { 524 | if matches!(self.error_on, ErrorOn::ArrayValue) { 525 | Err(MyError) 526 | } else { 527 | self.parser.array_value(array, value).unwrap(); 528 | Ok(()) 529 | } 530 | } 531 | 532 | fn array_is_empty(&self, array: &Self::Array) -> bool { 533 | self.parser.array_is_empty(array) 534 | } 535 | 536 | fn end_array(&mut self, array: Self::Array) -> Result { 537 | if matches!(self.error_on, ErrorOn::EndArray) { 538 | Err(MyError) 539 | } else { 540 | Ok(self.parser.end_array(array).unwrap()) 541 | } 542 | } 543 | 544 | fn kind_of(&self, value: &Self::Value) -> crate::parser::JsonKind { 545 | self.parser.kind_of(value) 546 | } 547 | } 548 | 549 | #[test] 550 | fn parse_delegate_error() { 551 | let payload = 552 | br#"{"a":1,"b":true,"c":"hello","d":[null, -1, 0, false, []],"e":{},"f":"error"}"#; 553 | Parser::parse_json_bytes_with_config( 554 | payload, 555 | ParseConfig::strict(), 556 | ErroringDelegate::new(ErrorOn::None), 557 | ) 558 | .expect("no errors"); 559 | 560 | for error_on in [ 561 | ErrorOn::Null, 562 | ErrorOn::Boolean(false), 563 | ErrorOn::Boolean(false), 564 | ErrorOn::Number("1"), 565 | ErrorOn::Number("-1"), 566 | ErrorOn::Number("0"), 567 | ErrorOn::String, 568 | ErrorOn::BeginObject, 569 | ErrorOn::ObjectKey, 570 | ErrorOn::ObjectValue, 571 | ErrorOn::EndObject, 572 | ErrorOn::BeginArray, 573 | ErrorOn::ArrayValue, 574 | ErrorOn::EndArray, 575 | ] { 576 | println!("Trying to error on {error_on:?}"); 577 | let err = Parser::parse_json_bytes(payload, ErroringDelegate::new(error_on)) 578 | .expect_err("expecting delegate error"); 579 | 580 | assert_eq!(err.kind(), &ErrorKind::ErrorFromDelegate(MyError)); 581 | } 582 | } 583 | 584 | #[test] 585 | fn illegal_types_at_root() { 586 | fn test_payload(json: &str) { 587 | assert_eq!( 588 | Document::from_json_with_config(json, ParseConfig::strict()) 589 | .unwrap_err() 590 | .kind, 591 | ErrorKind::PayloadsShouldBeObjectOrArray 592 | ); 593 | assert_eq!( 594 | Value::from_json_with_config(json, ParseConfig::strict()) 595 | .unwrap_err() 596 | .kind, 597 | ErrorKind::PayloadsShouldBeObjectOrArray 598 | ); 599 | } 600 | 601 | test_payload("null"); 602 | test_payload("true"); 603 | test_payload("1"); 604 | test_payload("\"\""); 605 | } 606 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_number_double_huge_neg_exp.json: -------------------------------------------------------------------------------- 1 | [123.456e-789] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_number_huge_exp.json: -------------------------------------------------------------------------------- 1 | [0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_number_neg_int_huge_exp.json: -------------------------------------------------------------------------------- 1 | [-1e+9999] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_number_pos_double_huge_exp.json: -------------------------------------------------------------------------------- 1 | [1.5e+9999] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_number_real_neg_overflow.json: -------------------------------------------------------------------------------- 1 | [-123123e100000] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_number_real_pos_overflow.json: -------------------------------------------------------------------------------- 1 | [123123e100000] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_number_real_underflow.json: -------------------------------------------------------------------------------- 1 | [123e-10000000] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_number_too_big_neg_int.json: -------------------------------------------------------------------------------- 1 | [-123123123123123123123123123123] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_number_too_big_pos_int.json: -------------------------------------------------------------------------------- 1 | [100000000000000000000] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_number_very_big_negative_int.json: -------------------------------------------------------------------------------- 1 | [-237462374673276894279832749832423479823246327846] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_object_key_lone_2nd_surrogate.json: -------------------------------------------------------------------------------- 1 | {"\uDFAA":0} -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_1st_surrogate_but_2nd_missing.json: -------------------------------------------------------------------------------- 1 | ["\uDADA"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_1st_valid_surrogate_2nd_invalid.json: -------------------------------------------------------------------------------- 1 | ["\uD888\u1234"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_UTF-16LE_with_BOM.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_UTF-16LE_with_BOM.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_UTF-8_invalid_sequence.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_UTF-8_invalid_sequence.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_UTF8_surrogate_U+D800.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_UTF8_surrogate_U+D800.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_incomplete_surrogate_and_escape_valid.json: -------------------------------------------------------------------------------- 1 | ["\uD800\n"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_incomplete_surrogate_pair.json: -------------------------------------------------------------------------------- 1 | ["\uDd1ea"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_incomplete_surrogates_escape_valid.json: -------------------------------------------------------------------------------- 1 | ["\uD800\uD800\n"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_invalid_lonely_surrogate.json: -------------------------------------------------------------------------------- 1 | ["\ud800"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_invalid_surrogate.json: -------------------------------------------------------------------------------- 1 | ["\ud800abc"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_invalid_utf-8.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_invalid_utf-8.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_inverted_surrogates_U+1D11E.json: -------------------------------------------------------------------------------- 1 | ["\uDd1e\uD834"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_iso_latin_1.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_iso_latin_1.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_lone_second_surrogate.json: -------------------------------------------------------------------------------- 1 | ["\uDFAA"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_lone_utf8_continuation_byte.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_lone_utf8_continuation_byte.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_not_in_unicode_range.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_not_in_unicode_range.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_overlong_sequence_2_bytes.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_overlong_sequence_2_bytes.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_overlong_sequence_6_bytes.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_overlong_sequence_6_bytes.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_overlong_sequence_6_bytes_null.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_overlong_sequence_6_bytes_null.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_truncated-utf-8.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_truncated-utf-8.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_utf16BE_no_BOM.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_utf16BE_no_BOM.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_string_utf16LE_no_BOM.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/i_string_utf16LE_no_BOM.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_structure_500_nested_arrays.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /tests/JSONTestSuite/i_structure_UTF-8_BOM_empty_object.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_1_true_without_comma.json: -------------------------------------------------------------------------------- 1 | [1 true] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_a_invalid_utf8.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/n_array_a_invalid_utf8.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_colon_instead_of_comma.json: -------------------------------------------------------------------------------- 1 | ["": 1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_comma_after_close.json: -------------------------------------------------------------------------------- 1 | [""], -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_comma_and_number.json: -------------------------------------------------------------------------------- 1 | [,1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_double_comma.json: -------------------------------------------------------------------------------- 1 | [1,,2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_double_extra_comma.json: -------------------------------------------------------------------------------- 1 | ["x",,] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_extra_close.json: -------------------------------------------------------------------------------- 1 | ["x"]] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_extra_comma.json: -------------------------------------------------------------------------------- 1 | ["",] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_incomplete.json: -------------------------------------------------------------------------------- 1 | ["x" -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_incomplete_invalid_value.json: -------------------------------------------------------------------------------- 1 | [x -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_inner_array_no_comma.json: -------------------------------------------------------------------------------- 1 | [3[4]] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_invalid_utf8.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/n_array_invalid_utf8.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_items_separated_by_semicolon.json: -------------------------------------------------------------------------------- 1 | [1:2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_just_comma.json: -------------------------------------------------------------------------------- 1 | [,] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_just_minus.json: -------------------------------------------------------------------------------- 1 | [-] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_missing_value.json: -------------------------------------------------------------------------------- 1 | [ , ""] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_newlines_unclosed.json: -------------------------------------------------------------------------------- 1 | ["a", 2 | 4 3 | ,1, -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_number_and_comma.json: -------------------------------------------------------------------------------- 1 | [1,] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_number_and_several_commas.json: -------------------------------------------------------------------------------- 1 | [1,,] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_spaces_vertical_tab_formfeed.json: -------------------------------------------------------------------------------- 1 | [" a"\f] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_star_inside.json: -------------------------------------------------------------------------------- 1 | [*] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_unclosed.json: -------------------------------------------------------------------------------- 1 | ["" -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_unclosed_trailing_comma.json: -------------------------------------------------------------------------------- 1 | [1, -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_unclosed_with_new_lines.json: -------------------------------------------------------------------------------- 1 | [1, 2 | 1 3 | ,1 -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_array_unclosed_with_object_inside.json: -------------------------------------------------------------------------------- 1 | [{} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_incomplete_false.json: -------------------------------------------------------------------------------- 1 | [fals] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_incomplete_null.json: -------------------------------------------------------------------------------- 1 | [nul] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_incomplete_true.json: -------------------------------------------------------------------------------- 1 | [tru] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_multidigit_number_then_00.json: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_++.json: -------------------------------------------------------------------------------- 1 | [++1234] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_+1.json: -------------------------------------------------------------------------------- 1 | [+1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_+Inf.json: -------------------------------------------------------------------------------- 1 | [+Inf] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_-01.json: -------------------------------------------------------------------------------- 1 | [-01] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_-1.0..json: -------------------------------------------------------------------------------- 1 | [-1.0.] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_-2..json: -------------------------------------------------------------------------------- 1 | [-2.] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_-NaN.json: -------------------------------------------------------------------------------- 1 | [-NaN] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_.-1.json: -------------------------------------------------------------------------------- 1 | [.-1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_.2e-3.json: -------------------------------------------------------------------------------- 1 | [.2e-3] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_0.1.2.json: -------------------------------------------------------------------------------- 1 | [0.1.2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_0.3e+.json: -------------------------------------------------------------------------------- 1 | [0.3e+] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_0.3e.json: -------------------------------------------------------------------------------- 1 | [0.3e] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_0.e1.json: -------------------------------------------------------------------------------- 1 | [0.e1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_0_capital_E+.json: -------------------------------------------------------------------------------- 1 | [0E+] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_0_capital_E.json: -------------------------------------------------------------------------------- 1 | [0E] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_0e+.json: -------------------------------------------------------------------------------- 1 | [0e+] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_0e.json: -------------------------------------------------------------------------------- 1 | [0e] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_1.0e+.json: -------------------------------------------------------------------------------- 1 | [1.0e+] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_1.0e-.json: -------------------------------------------------------------------------------- 1 | [1.0e-] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_1.0e.json: -------------------------------------------------------------------------------- 1 | [1.0e] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_1_000.json: -------------------------------------------------------------------------------- 1 | [1 000.0] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_1eE2.json: -------------------------------------------------------------------------------- 1 | [1eE2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_2.e+3.json: -------------------------------------------------------------------------------- 1 | [2.e+3] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_2.e-3.json: -------------------------------------------------------------------------------- 1 | [2.e-3] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_2.e3.json: -------------------------------------------------------------------------------- 1 | [2.e3] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_9.e+.json: -------------------------------------------------------------------------------- 1 | [9.e+] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_Inf.json: -------------------------------------------------------------------------------- 1 | [Inf] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_NaN.json: -------------------------------------------------------------------------------- 1 | [NaN] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_U+FF11_fullwidth_digit_one.json: -------------------------------------------------------------------------------- 1 | [1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_expression.json: -------------------------------------------------------------------------------- 1 | [1+2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_hex_1_digit.json: -------------------------------------------------------------------------------- 1 | [0x1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_hex_2_digits.json: -------------------------------------------------------------------------------- 1 | [0x42] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_infinity.json: -------------------------------------------------------------------------------- 1 | [Infinity] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_invalid+-.json: -------------------------------------------------------------------------------- 1 | [0e+-1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_invalid-negative-real.json: -------------------------------------------------------------------------------- 1 | [-123.123foo] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_invalid-utf-8-in-bigger-int.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/n_number_invalid-utf-8-in-bigger-int.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_invalid-utf-8-in-exponent.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/n_number_invalid-utf-8-in-exponent.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_invalid-utf-8-in-int.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/n_number_invalid-utf-8-in-int.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_minus_infinity.json: -------------------------------------------------------------------------------- 1 | [-Infinity] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_minus_sign_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | [-foo] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_minus_space_1.json: -------------------------------------------------------------------------------- 1 | [- 1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_neg_int_starting_with_zero.json: -------------------------------------------------------------------------------- 1 | [-012] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_neg_real_without_int_part.json: -------------------------------------------------------------------------------- 1 | [-.123] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_neg_with_garbage_at_end.json: -------------------------------------------------------------------------------- 1 | [-1x] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_real_garbage_after_e.json: -------------------------------------------------------------------------------- 1 | [1ea] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_real_with_invalid_utf8_after_e.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/n_number_real_with_invalid_utf8_after_e.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_real_without_fractional_part.json: -------------------------------------------------------------------------------- 1 | [1.] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_starting_with_dot.json: -------------------------------------------------------------------------------- 1 | [.123] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_with_alpha.json: -------------------------------------------------------------------------------- 1 | [1.2a-3] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_with_alpha_char.json: -------------------------------------------------------------------------------- 1 | [1.8011670033376514H-308] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_number_with_leading_zero.json: -------------------------------------------------------------------------------- 1 | [012] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_bad_value.json: -------------------------------------------------------------------------------- 1 | ["x", truth] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_bracket_key.json: -------------------------------------------------------------------------------- 1 | {[: "x"} 2 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_comma_instead_of_colon.json: -------------------------------------------------------------------------------- 1 | {"x", null} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_double_colon.json: -------------------------------------------------------------------------------- 1 | {"x"::"b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_emoji.json: -------------------------------------------------------------------------------- 1 | {🇨🇭} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_garbage_at_end.json: -------------------------------------------------------------------------------- 1 | {"a":"a" 123} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_key_with_single_quotes.json: -------------------------------------------------------------------------------- 1 | {key: 'value'} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_lone_continuation_byte_in_key_and_trailing_comma.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/n_object_lone_continuation_byte_in_key_and_trailing_comma.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_missing_colon.json: -------------------------------------------------------------------------------- 1 | {"a" b} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_missing_key.json: -------------------------------------------------------------------------------- 1 | {:"b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_missing_semicolon.json: -------------------------------------------------------------------------------- 1 | {"a" "b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_missing_value.json: -------------------------------------------------------------------------------- 1 | {"a": -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_no-colon.json: -------------------------------------------------------------------------------- 1 | {"a" -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_non_string_key.json: -------------------------------------------------------------------------------- 1 | {1:1} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_non_string_key_but_huge_number_instead.json: -------------------------------------------------------------------------------- 1 | {9999E9999:1} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_repeated_null_null.json: -------------------------------------------------------------------------------- 1 | {null:null,null:null} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_several_trailing_commas.json: -------------------------------------------------------------------------------- 1 | {"id":0,,,,,} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_single_quote.json: -------------------------------------------------------------------------------- 1 | {'a':0} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_trailing_comma.json: -------------------------------------------------------------------------------- 1 | {"id":0,} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_trailing_comment.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}/**/ -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_trailing_comment_open.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}/**// -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_trailing_comment_slash_open.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}// -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_trailing_comment_slash_open_incomplete.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}/ -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_two_commas_in_a_row.json: -------------------------------------------------------------------------------- 1 | {"a":"b",,"c":"d"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_unquoted_key.json: -------------------------------------------------------------------------------- 1 | {a: "b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_unterminated-value.json: -------------------------------------------------------------------------------- 1 | {"a":"a -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_with_single_string.json: -------------------------------------------------------------------------------- 1 | { "foo" : "bar", "a" } -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_object_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}# -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_single_space.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_1_surrogate_then_escape.json: -------------------------------------------------------------------------------- 1 | ["\uD800\"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_1_surrogate_then_escape_u.json: -------------------------------------------------------------------------------- 1 | ["\uD800\u"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_1_surrogate_then_escape_u1.json: -------------------------------------------------------------------------------- 1 | ["\uD800\u1"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_1_surrogate_then_escape_u1x.json: -------------------------------------------------------------------------------- 1 | ["\uD800\u1x"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_accentuated_char_no_quotes.json: -------------------------------------------------------------------------------- 1 | [é] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_backslash_00.json: -------------------------------------------------------------------------------- 1 | ["\"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_escape_x.json: -------------------------------------------------------------------------------- 1 | ["\x00"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_escaped_backslash_bad.json: -------------------------------------------------------------------------------- 1 | ["\\\"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_escaped_ctrl_char_tab.json: -------------------------------------------------------------------------------- 1 | ["\ "] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_escaped_emoji.json: -------------------------------------------------------------------------------- 1 | ["\🌀"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_incomplete_escape.json: -------------------------------------------------------------------------------- 1 | ["\"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_incomplete_escaped_character.json: -------------------------------------------------------------------------------- 1 | ["\u00A"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_incomplete_surrogate.json: -------------------------------------------------------------------------------- 1 | ["\uD834\uDd"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_incomplete_surrogate_escape_invalid.json: -------------------------------------------------------------------------------- 1 | ["\uD800\uD800\x"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_invalid-utf-8-in-escape.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/n_string_invalid-utf-8-in-escape.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_invalid_backslash_esc.json: -------------------------------------------------------------------------------- 1 | ["\a"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_invalid_unicode_escape.json: -------------------------------------------------------------------------------- 1 | ["\uqqqq"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_invalid_utf8_after_escape.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/n_string_invalid_utf8_after_escape.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_leading_uescaped_thinspace.json: -------------------------------------------------------------------------------- 1 | [\u0020"asd"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_no_quotes_with_bad_escape.json: -------------------------------------------------------------------------------- 1 | [\n] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_single_doublequote.json: -------------------------------------------------------------------------------- 1 | " -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_single_quote.json: -------------------------------------------------------------------------------- 1 | ['single quote'] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_single_string_no_double_quotes.json: -------------------------------------------------------------------------------- 1 | abc -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_start_escape_unclosed.json: -------------------------------------------------------------------------------- 1 | ["\ -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_unescaped_ctrl_char.json: -------------------------------------------------------------------------------- 1 | ["aa"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_unescaped_newline.json: -------------------------------------------------------------------------------- 1 | ["new 2 | line"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_unescaped_tab.json: -------------------------------------------------------------------------------- 1 | [" "] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_unicode_CapitalU.json: -------------------------------------------------------------------------------- 1 | "\UA66D" -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_string_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | ""x -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_U+2060_word_joined.json: -------------------------------------------------------------------------------- 1 | [⁠] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_UTF8_BOM_no_data.json: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_angle_bracket_..json: -------------------------------------------------------------------------------- 1 | <.> -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_angle_bracket_null.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_array_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | [1]x -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_array_with_extra_array_close.json: -------------------------------------------------------------------------------- 1 | [1]] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_array_with_unclosed_string.json: -------------------------------------------------------------------------------- 1 | ["asd] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_ascii-unicode-identifier.json: -------------------------------------------------------------------------------- 1 | aå -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_capitalized_True.json: -------------------------------------------------------------------------------- 1 | [True] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_close_unopened_array.json: -------------------------------------------------------------------------------- 1 | 1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_comma_instead_of_closing_brace.json: -------------------------------------------------------------------------------- 1 | {"x": true, -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_double_array.json: -------------------------------------------------------------------------------- 1 | [][] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_end_array.json: -------------------------------------------------------------------------------- 1 | ] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_incomplete_UTF8_BOM.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/n_structure_incomplete_UTF8_BOM.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_lone-invalid-utf-8.json: -------------------------------------------------------------------------------- 1 | � -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_lone-open-bracket.json: -------------------------------------------------------------------------------- 1 | [ -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_no_data.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khonsulabs/justjson/56a65678e3980698f49d12bbefae3d8c9a5dd721/tests/JSONTestSuite/n_structure_no_data.json -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_null-byte-outside-string.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_number_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | 2@ -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_object_followed_by_closing_object.json: -------------------------------------------------------------------------------- 1 | {}} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_object_unclosed_no_value.json: -------------------------------------------------------------------------------- 1 | {"": -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_object_with_comment.json: -------------------------------------------------------------------------------- 1 | {"a":/*comment*/"b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_object_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | {"a": true} "x" -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_array_apostrophe.json: -------------------------------------------------------------------------------- 1 | [' -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_array_comma.json: -------------------------------------------------------------------------------- 1 | [, -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_array_open_object.json: -------------------------------------------------------------------------------- 1 | [{ -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_array_open_string.json: -------------------------------------------------------------------------------- 1 | ["a -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_array_string.json: -------------------------------------------------------------------------------- 1 | ["a" -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_object.json: -------------------------------------------------------------------------------- 1 | { -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_object_close_array.json: -------------------------------------------------------------------------------- 1 | {] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_object_comma.json: -------------------------------------------------------------------------------- 1 | {, -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_object_open_array.json: -------------------------------------------------------------------------------- 1 | {[ -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_object_open_string.json: -------------------------------------------------------------------------------- 1 | {"a -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_object_string_with_apostrophes.json: -------------------------------------------------------------------------------- 1 | {'a' -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_open_open.json: -------------------------------------------------------------------------------- 1 | ["\{["\{["\{["\{ -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_single_eacute.json: -------------------------------------------------------------------------------- 1 | � -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_single_star.json: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_trailing_#.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}#{} -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_uescaped_LF_before_string.json: -------------------------------------------------------------------------------- 1 | [\u000A""] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_unclosed_array.json: -------------------------------------------------------------------------------- 1 | [1 -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_unclosed_array_partial_null.json: -------------------------------------------------------------------------------- 1 | [ false, nul -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_unclosed_array_unfinished_false.json: -------------------------------------------------------------------------------- 1 | [ true, fals -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_unclosed_array_unfinished_true.json: -------------------------------------------------------------------------------- 1 | [ false, tru -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_unclosed_object.json: -------------------------------------------------------------------------------- 1 | {"asd":"asd" -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_unicode-identifier.json: -------------------------------------------------------------------------------- 1 | å -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_whitespace_U+2060_word_joiner.json: -------------------------------------------------------------------------------- 1 | [⁠] -------------------------------------------------------------------------------- /tests/JSONTestSuite/n_structure_whitespace_formfeed.json: -------------------------------------------------------------------------------- 1 | [ ] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_array_arraysWithSpaces.json: -------------------------------------------------------------------------------- 1 | [[] ] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_array_empty-string.json: -------------------------------------------------------------------------------- 1 | [""] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_array_empty.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_array_ending_with_newline.json: -------------------------------------------------------------------------------- 1 | ["a"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_array_false.json: -------------------------------------------------------------------------------- 1 | [false] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_array_heterogeneous.json: -------------------------------------------------------------------------------- 1 | [null, 1, "1", {}] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_array_null.json: -------------------------------------------------------------------------------- 1 | [null] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_array_with_1_and_newline.json: -------------------------------------------------------------------------------- 1 | [1 2 | ] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_array_with_leading_space.json: -------------------------------------------------------------------------------- 1 | [1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_array_with_several_null.json: -------------------------------------------------------------------------------- 1 | [1,null,null,null,2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_array_with_trailing_space.json: -------------------------------------------------------------------------------- 1 | [2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number.json: -------------------------------------------------------------------------------- 1 | [123e65] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_0e+1.json: -------------------------------------------------------------------------------- 1 | [0e+1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_0e1.json: -------------------------------------------------------------------------------- 1 | [0e1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_after_space.json: -------------------------------------------------------------------------------- 1 | [ 4] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_double_close_to_zero.json: -------------------------------------------------------------------------------- 1 | [-0.000000000000000000000000000000000000000000000000000000000000000000000000000001] 2 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_int_with_exp.json: -------------------------------------------------------------------------------- 1 | [20e1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_minus_zero.json: -------------------------------------------------------------------------------- 1 | [-0] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_negative_int.json: -------------------------------------------------------------------------------- 1 | [-123] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_negative_one.json: -------------------------------------------------------------------------------- 1 | [-1] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_negative_zero.json: -------------------------------------------------------------------------------- 1 | [-0] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_real_capital_e.json: -------------------------------------------------------------------------------- 1 | [1E22] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_real_capital_e_neg_exp.json: -------------------------------------------------------------------------------- 1 | [1E-2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_real_capital_e_pos_exp.json: -------------------------------------------------------------------------------- 1 | [1E+2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_real_exponent.json: -------------------------------------------------------------------------------- 1 | [123e45] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_real_fraction_exponent.json: -------------------------------------------------------------------------------- 1 | [123.456e78] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_real_neg_exp.json: -------------------------------------------------------------------------------- 1 | [1e-2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_real_pos_exponent.json: -------------------------------------------------------------------------------- 1 | [1e+2] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_simple_int.json: -------------------------------------------------------------------------------- 1 | [123] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_number_simple_real.json: -------------------------------------------------------------------------------- 1 | [123.456789] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_object.json: -------------------------------------------------------------------------------- 1 | {"asd":"sdf", "dfg":"fgh"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_object_basic.json: -------------------------------------------------------------------------------- 1 | {"asd":"sdf"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_object_duplicated_key.json: -------------------------------------------------------------------------------- 1 | {"a":"b","a":"c"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_object_duplicated_key_and_value.json: -------------------------------------------------------------------------------- 1 | {"a":"b","a":"b"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_object_empty.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_object_empty_key.json: -------------------------------------------------------------------------------- 1 | {"":0} -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_object_escaped_null_in_key.json: -------------------------------------------------------------------------------- 1 | {"foo\u0000bar": 42} -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_object_extreme_numbers.json: -------------------------------------------------------------------------------- 1 | { "min": -1.0e+28, "max": 1.0e+28 } -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_object_long_strings.json: -------------------------------------------------------------------------------- 1 | {"x":[{"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}], "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_object_simple.json: -------------------------------------------------------------------------------- 1 | {"a":[]} -------------------------------------------------------------------------------- /tests/JSONTestSuite/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/y_object_with_newlines.json: -------------------------------------------------------------------------------- 1 | { 2 | "a": "b" 3 | } -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_1_2_3_bytes_UTF-8_sequences.json: -------------------------------------------------------------------------------- 1 | ["\u0060\u012a\u12AB"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_accepted_surrogate_pair.json: -------------------------------------------------------------------------------- 1 | ["\uD801\udc37"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_accepted_surrogate_pairs.json: -------------------------------------------------------------------------------- 1 | ["\ud83d\ude39\ud83d\udc8d"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_allowed_escapes.json: -------------------------------------------------------------------------------- 1 | ["\"\\\/\b\f\n\r\t"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_backslash_and_u_escaped_zero.json: -------------------------------------------------------------------------------- 1 | ["\\u0000"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_backslash_doublequotes.json: -------------------------------------------------------------------------------- 1 | ["\""] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_comments.json: -------------------------------------------------------------------------------- 1 | ["a/*b*/c/*d//e"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_double_escape_a.json: -------------------------------------------------------------------------------- 1 | ["\\a"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_double_escape_n.json: -------------------------------------------------------------------------------- 1 | ["\\n"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_escaped_control_character.json: -------------------------------------------------------------------------------- 1 | ["\u0012"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_escaped_noncharacter.json: -------------------------------------------------------------------------------- 1 | ["\uFFFF"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_in_array.json: -------------------------------------------------------------------------------- 1 | ["asd"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_in_array_with_leading_space.json: -------------------------------------------------------------------------------- 1 | [ "asd"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_last_surrogates_1_and_2.json: -------------------------------------------------------------------------------- 1 | ["\uDBFF\uDFFF"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_nbsp_uescaped.json: -------------------------------------------------------------------------------- 1 | ["new\u00A0line"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_nonCharacterInUTF-8_U+10FFFF.json: -------------------------------------------------------------------------------- 1 | ["􏿿"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_nonCharacterInUTF-8_U+FFFF.json: -------------------------------------------------------------------------------- 1 | ["￿"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_null_escape.json: -------------------------------------------------------------------------------- 1 | ["\u0000"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_one-byte-utf-8.json: -------------------------------------------------------------------------------- 1 | ["\u002c"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_pi.json: -------------------------------------------------------------------------------- 1 | ["π"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_reservedCharacterInUTF-8_U+1BFFF.json: -------------------------------------------------------------------------------- 1 | ["𛿿"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_simple_ascii.json: -------------------------------------------------------------------------------- 1 | ["asd "] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_space.json: -------------------------------------------------------------------------------- 1 | " " -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json: -------------------------------------------------------------------------------- 1 | ["\uD834\uDd1e"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_three-byte-utf-8.json: -------------------------------------------------------------------------------- 1 | ["\u0821"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_two-byte-utf-8.json: -------------------------------------------------------------------------------- 1 | ["\u0123"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_u+2028_line_sep.json: -------------------------------------------------------------------------------- 1 | ["
"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_u+2029_par_sep.json: -------------------------------------------------------------------------------- 1 | ["
"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_uEscape.json: -------------------------------------------------------------------------------- 1 | ["\u0061\u30af\u30EA\u30b9"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_uescaped_newline.json: -------------------------------------------------------------------------------- 1 | ["new\u000Aline"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_unescaped_char_delete.json: -------------------------------------------------------------------------------- 1 | [""] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_unicode.json: -------------------------------------------------------------------------------- 1 | ["\uA66D"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_unicodeEscapedBackslash.json: -------------------------------------------------------------------------------- 1 | ["\u005C"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_unicode_2.json: -------------------------------------------------------------------------------- 1 | ["⍂㈴⍂"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_unicode_U+10FFFE_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uDBFF\uDFFE"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_unicode_U+1FFFE_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uD83F\uDFFE"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json: -------------------------------------------------------------------------------- 1 | ["\u200B"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_unicode_U+2064_invisible_plus.json: -------------------------------------------------------------------------------- 1 | ["\u2064"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_unicode_U+FDD0_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uFDD0"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_unicode_U+FFFE_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uFFFE"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_unicode_escaped_double_quote.json: -------------------------------------------------------------------------------- 1 | ["\u0022"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_utf8.json: -------------------------------------------------------------------------------- 1 | ["€𝄞"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_string_with_del_character.json: -------------------------------------------------------------------------------- 1 | ["aa"] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_structure_lonely_false.json: -------------------------------------------------------------------------------- 1 | false -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_structure_lonely_int.json: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_structure_lonely_negative_real.json: -------------------------------------------------------------------------------- 1 | -0.1 -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_structure_lonely_null.json: -------------------------------------------------------------------------------- 1 | null -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_structure_lonely_string.json: -------------------------------------------------------------------------------- 1 | "asd" -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_structure_lonely_true.json: -------------------------------------------------------------------------------- 1 | true -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_structure_string_empty.json: -------------------------------------------------------------------------------- 1 | "" -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_structure_trailing_newline.json: -------------------------------------------------------------------------------- 1 | ["a"] 2 | -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_structure_true_in_array.json: -------------------------------------------------------------------------------- 1 | [true] -------------------------------------------------------------------------------- /tests/JSONTestSuite/y_structure_whitespace_array.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /tests/jsonorg.rs: -------------------------------------------------------------------------------- 1 | use justjson::parser::{ParseConfig, Parser}; 2 | #[cfg(feature = "alloc")] 3 | use justjson::{doc::Document, Value}; 4 | 5 | macro_rules! json_org_test { 6 | ($name:ident) => { 7 | #[test] 8 | fn $name() { 9 | let src = include_bytes!(concat!("./jsonorg/", stringify!($name), ".json")); 10 | let src_str = std::str::from_utf8(src).unwrap(); 11 | let config = ParseConfig::strict().with_recursion_limit(19); 12 | 13 | if stringify!($name).starts_with("pass") { 14 | Parser::validate_json_bytes_with_config(src, config) 15 | .expect("failed to parse success case"); 16 | Parser::validate_json_with_config(src_str, config) 17 | .expect("failed to parse success case"); 18 | #[cfg(feature = "alloc")] 19 | { 20 | Value::from_json_bytes_with_config(src, config) 21 | .expect("failed to parse success case"); 22 | Value::from_json_with_config(src_str, config) 23 | .expect("failed to parse success case"); 24 | 25 | Document::from_json_bytes_with_config(src, config) 26 | .expect("failed to parse success case"); 27 | Document::from_json_with_config(src_str, config) 28 | .expect("failed to parse success case"); 29 | } 30 | } else { 31 | Parser::validate_json_bytes_with_config(src, config) 32 | .expect_err("success on failure case"); 33 | Parser::validate_json_with_config(src_str, config) 34 | .expect_err("success on failure case"); 35 | #[cfg(feature = "alloc")] 36 | { 37 | Value::from_json_bytes_with_config(src, config) 38 | .expect_err("success on failure case"); 39 | Value::from_json_with_config(src_str, config) 40 | .expect_err("success on failure case"); 41 | 42 | Document::from_json_bytes_with_config(src, config) 43 | .expect_err("success on failure case"); 44 | Document::from_json_with_config(src_str, config) 45 | .expect_err("success on failure case"); 46 | } 47 | } 48 | } 49 | }; 50 | } 51 | 52 | json_org_test!(pass1); 53 | json_org_test!(pass2); 54 | json_org_test!(pass3); 55 | 56 | json_org_test!(fail1); 57 | json_org_test!(fail2); 58 | json_org_test!(fail3); 59 | json_org_test!(fail4); 60 | json_org_test!(fail5); 61 | json_org_test!(fail6); 62 | json_org_test!(fail7); 63 | json_org_test!(fail8); 64 | json_org_test!(fail9); 65 | json_org_test!(fail10); 66 | json_org_test!(fail11); 67 | json_org_test!(fail12); 68 | json_org_test!(fail13); 69 | json_org_test!(fail14); 70 | json_org_test!(fail15); 71 | json_org_test!(fail16); 72 | json_org_test!(fail17); 73 | json_org_test!(fail18); 74 | json_org_test!(fail19); 75 | json_org_test!(fail20); 76 | json_org_test!(fail21); 77 | json_org_test!(fail22); 78 | json_org_test!(fail23); 79 | json_org_test!(fail24); 80 | json_org_test!(fail25); 81 | json_org_test!(fail26); 82 | json_org_test!(fail27); 83 | json_org_test!(fail28); 84 | json_org_test!(fail29); 85 | json_org_test!(fail30); 86 | json_org_test!(fail31); 87 | json_org_test!(fail32); 88 | json_org_test!(fail33); 89 | -------------------------------------------------------------------------------- /tests/jsonorg/fail1.json: -------------------------------------------------------------------------------- 1 | "A JSON payload should be an object or array, not a string." -------------------------------------------------------------------------------- /tests/jsonorg/fail10.json: -------------------------------------------------------------------------------- 1 | {"Extra value after close": true} "misplaced quoted value" -------------------------------------------------------------------------------- /tests/jsonorg/fail11.json: -------------------------------------------------------------------------------- 1 | {"Illegal expression": 1 + 2} -------------------------------------------------------------------------------- /tests/jsonorg/fail12.json: -------------------------------------------------------------------------------- 1 | {"Illegal invocation": alert()} -------------------------------------------------------------------------------- /tests/jsonorg/fail13.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot have leading zeroes": 013} -------------------------------------------------------------------------------- /tests/jsonorg/fail14.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot be hex": 0x14} -------------------------------------------------------------------------------- /tests/jsonorg/fail15.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \x15"] -------------------------------------------------------------------------------- /tests/jsonorg/fail16.json: -------------------------------------------------------------------------------- 1 | [\naked] -------------------------------------------------------------------------------- /tests/jsonorg/fail17.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \017"] -------------------------------------------------------------------------------- /tests/jsonorg/fail18.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /tests/jsonorg/fail19.json: -------------------------------------------------------------------------------- 1 | {"Missing colon" null} -------------------------------------------------------------------------------- /tests/jsonorg/fail2.json: -------------------------------------------------------------------------------- 1 | ["Unclosed array" -------------------------------------------------------------------------------- /tests/jsonorg/fail20.json: -------------------------------------------------------------------------------- 1 | {"Double colon":: null} -------------------------------------------------------------------------------- /tests/jsonorg/fail21.json: -------------------------------------------------------------------------------- 1 | {"Comma instead of colon", null} -------------------------------------------------------------------------------- /tests/jsonorg/fail22.json: -------------------------------------------------------------------------------- 1 | ["Colon instead of comma": false] -------------------------------------------------------------------------------- /tests/jsonorg/fail23.json: -------------------------------------------------------------------------------- 1 | ["Bad value", truth] -------------------------------------------------------------------------------- /tests/jsonorg/fail24.json: -------------------------------------------------------------------------------- 1 | ['single quote'] -------------------------------------------------------------------------------- /tests/jsonorg/fail25.json: -------------------------------------------------------------------------------- 1 | [" tab character in string "] -------------------------------------------------------------------------------- /tests/jsonorg/fail26.json: -------------------------------------------------------------------------------- 1 | ["tab\ character\ in\ string\ "] -------------------------------------------------------------------------------- /tests/jsonorg/fail27.json: -------------------------------------------------------------------------------- 1 | ["line 2 | break"] -------------------------------------------------------------------------------- /tests/jsonorg/fail28.json: -------------------------------------------------------------------------------- 1 | ["line\ 2 | break"] -------------------------------------------------------------------------------- /tests/jsonorg/fail29.json: -------------------------------------------------------------------------------- 1 | [0e] -------------------------------------------------------------------------------- /tests/jsonorg/fail3.json: -------------------------------------------------------------------------------- 1 | {unquoted_key: "keys must be quoted"} -------------------------------------------------------------------------------- /tests/jsonorg/fail30.json: -------------------------------------------------------------------------------- 1 | [0e+] -------------------------------------------------------------------------------- /tests/jsonorg/fail31.json: -------------------------------------------------------------------------------- 1 | [0e+-1] -------------------------------------------------------------------------------- /tests/jsonorg/fail32.json: -------------------------------------------------------------------------------- 1 | {"Comma instead if closing brace": true, -------------------------------------------------------------------------------- /tests/jsonorg/fail33.json: -------------------------------------------------------------------------------- 1 | ["mismatch"} -------------------------------------------------------------------------------- /tests/jsonorg/fail4.json: -------------------------------------------------------------------------------- 1 | ["extra comma",] -------------------------------------------------------------------------------- /tests/jsonorg/fail5.json: -------------------------------------------------------------------------------- 1 | ["double extra comma",,] -------------------------------------------------------------------------------- /tests/jsonorg/fail6.json: -------------------------------------------------------------------------------- 1 | [ , "<-- missing value"] -------------------------------------------------------------------------------- /tests/jsonorg/fail7.json: -------------------------------------------------------------------------------- 1 | ["Comma after the close"], -------------------------------------------------------------------------------- /tests/jsonorg/fail8.json: -------------------------------------------------------------------------------- 1 | ["Extra close"]] -------------------------------------------------------------------------------- /tests/jsonorg/fail9.json: -------------------------------------------------------------------------------- 1 | {"Extra comma": true,} -------------------------------------------------------------------------------- /tests/jsonorg/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/jsonorg/pass2.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /tests/jsonorg/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/roundtrip.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | 3 | use justjson::doc::Document; 4 | use justjson::Value; 5 | 6 | #[test] 7 | fn suite() { 8 | for entry in fs::read_dir("./tests/roundtrip/").unwrap() { 9 | let entry = entry.unwrap(); 10 | let name = entry.file_name(); 11 | let Some(name) = name.to_str() else { continue; }; 12 | if name.ends_with(".json") { 13 | println!("Testing {name}"); 14 | let contents = fs::read(entry.path()).unwrap(); 15 | let value = Value::from_json_bytes(&contents).unwrap(); 16 | let as_json = value.to_json(); 17 | assert_eq!(as_json.as_bytes(), contents); 18 | 19 | // Test that Document -> Value conversion works for this value as 20 | // well. 21 | let doc = Document::from_json_bytes(&contents).unwrap(); 22 | assert_eq!(Value::from(doc), value); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip01.json: -------------------------------------------------------------------------------- 1 | [null] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip02.json: -------------------------------------------------------------------------------- 1 | [true] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip03.json: -------------------------------------------------------------------------------- 1 | [false] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip04.json: -------------------------------------------------------------------------------- 1 | [0] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip05.json: -------------------------------------------------------------------------------- 1 | ["foo"] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip06.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip07.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip08.json: -------------------------------------------------------------------------------- 1 | [0,1] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip09.json: -------------------------------------------------------------------------------- 1 | {"foo":"bar"} -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip10.json: -------------------------------------------------------------------------------- 1 | {"a":null,"foo":"bar"} -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip11.json: -------------------------------------------------------------------------------- 1 | [-1] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip12.json: -------------------------------------------------------------------------------- 1 | [-2147483648] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip13.json: -------------------------------------------------------------------------------- 1 | [-1234567890123456789] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip14.json: -------------------------------------------------------------------------------- 1 | [-9223372036854775808] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip15.json: -------------------------------------------------------------------------------- 1 | [1] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip16.json: -------------------------------------------------------------------------------- 1 | [2147483647] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip17.json: -------------------------------------------------------------------------------- 1 | [4294967295] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip18.json: -------------------------------------------------------------------------------- 1 | [1234567890123456789] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip19.json: -------------------------------------------------------------------------------- 1 | [9223372036854775807] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip20.json: -------------------------------------------------------------------------------- 1 | [0.0] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip21.json: -------------------------------------------------------------------------------- 1 | [-0.0] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip22.json: -------------------------------------------------------------------------------- 1 | [1.2345] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip23.json: -------------------------------------------------------------------------------- 1 | [-1.2345] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip24.json: -------------------------------------------------------------------------------- 1 | [5e-324] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip25.json: -------------------------------------------------------------------------------- 1 | [2.225073858507201e-308] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip26.json: -------------------------------------------------------------------------------- 1 | [2.2250738585072014e-308] -------------------------------------------------------------------------------- /tests/roundtrip/roundtrip27.json: -------------------------------------------------------------------------------- 1 | [1.7976931348623157e308] -------------------------------------------------------------------------------- /xtask/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xtask" 3 | version = "0.0.0" 4 | edition = "2021" 5 | publish = false 6 | 7 | [dependencies] 8 | khonsu-tools = { git = "https://github.com/khonsulabs/khonsu-tools.git", branch = "main" } 9 | -------------------------------------------------------------------------------- /xtask/src/main.rs: -------------------------------------------------------------------------------- 1 | use khonsu_tools::universal::clap::Parser; 2 | use khonsu_tools::universal::{anyhow, DefaultConfig}; 3 | use khonsu_tools::Commands; 4 | 5 | fn main() -> anyhow::Result<()> { 6 | Commands::parse().execute::() 7 | } 8 | 9 | enum Config {} 10 | 11 | impl khonsu_tools::Config for Config { 12 | type Publish = Self; 13 | type Universal = Self; 14 | } 15 | 16 | impl khonsu_tools::universal::Config for Config { 17 | type Audit = DefaultConfig; 18 | type CodeCoverage = Self; 19 | } 20 | 21 | impl khonsu_tools::publish::Config for Config { 22 | fn paths() -> Vec { 23 | vec![String::from(".")] 24 | } 25 | } 26 | 27 | impl khonsu_tools::universal::code_coverage::Config for Config { 28 | fn cargo_args() -> Vec { 29 | vec![ 30 | String::from("test"), 31 | String::from("--workspace"), 32 | String::from("--all-targets"), 33 | String::from("--features"), 34 | String::from("heapless"), 35 | ] 36 | } 37 | } 38 | --------------------------------------------------------------------------------