Repository navigation
to_string_pretty: valid JSON for tuple variants - #487
Merged
Merged
Conversation
Licenser
enabled auto-merge (squash)
October 3, 2026 14:28
`SerializeTupleVariant::end` for the pretty serializer closed the array
of fields with `}` instead of `]` and never closed the object
`{"Variant": ...}` that `serialize_tuple_variant` opened:
enum E { C(i64, String), Z() }
to_string_pretty(&E::C(1, "s".into())) {"C": [1, "s" } (one line per item)
to_string_pretty(&E::Z()) {"Z": []
Neither is JSON; the compact serializer and serde_json write
`{"C": [1, "s"]}`. `end` now closes the array (when it has fields; an
empty one was already written as `[]`) and then the object, with the
same indentation as serde_json.
Test: `pretty_print_tuple_variant` (fails before this change), which
also compares a nested case with serde_json::to_string_pretty.
Found by a differential fuzzer (serde_json, simd-json, sonic-rs, jiter)
extended to typed serialization.
Licenser
force-pushed
the
pr/pretty-tuple-variant
branch
from
October 3, 2026 15:53
280ee02 to
2c94b92
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: to_string_pretty wrote invalid JSON for tuple variants
SerializeTupleVariant::endfor the pretty serializer closed the arrayof fields with
}instead of]and never closed the object{"Variant": ...}thatserialize_tuple_variantopened:Neither is JSON; the compact serializer and serde_json write
{"C": [1, "s"]}.endnow closes the array (when it has fields; anempty one was already written as
[]) and then the object, with thesame indentation as serde_json.
Test:
pretty_print_tuple_variant(fails before this change), whichalso compares a nested case with serde_json::to_string_pretty.
Testing
Each commit adds a regression test that fails before the change. The full test suite passes and
cargo fmt --checkis clean on the changed files.Found with a differential fuzzer comparing serde_json, simd-json, sonic-rs and jiter.