fix(jsonview): preserve literal object keys in pretty output - #86
Open
sylvesterkaczmarek wants to merge 2 commits into
Open
fix(jsonview): preserve literal object keys in pretty output#86sylvesterkaczmarek wants to merge 2 commits into
sylvesterkaczmarek wants to merge 2 commits into
Conversation
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.
Summary
Use literal object-member lookup when rendering pretty JSON so keys containing GJSON path syntax display their own values.
Fixes #81.
Problem
The pretty renderer enumerates real JSON member names with
@keys, then looks each value up again throughresult.Get(key.Str).Result.Getdoes not perform literal map lookup. It parses the supplied string as a GJSON path. That changes the meaning of keys such as"a.b".For example:
{ "a.b": "literal-value", "a": { "b": "nested-value" } }The current renderer enumerates
"a.b"correctly but then resolvesresult.Get("a.b")to the nesteda.bvalue. The row for the literal top-level key can therefore display"nested-value", and"literal-value"may never appear in the output.Root cause
Two incompatible access models are mixed in the same loop:
@keysreturns literal object member names;Result.Gettreats those names as path expressions.This is only safe for keys that contain no GJSON path metacharacters.
Fix
Materialize the object's literal map once:
and then index it with the enumerated key:
This also avoids repeatedly reparsing each key as a path.
Regression coverage
Added a focused regression with both:
"a.b"whose value is"literal-value";a -> bvalue named"nested-value".The test requires both values to remain visible in static pretty output. On current
main, the literal value is lost because the dotted key resolves the nested path.Validation
The branch is based directly on upstream
mainatd082a010f7c6cacf407d8a1581446a7857f9f1bband is not behind it.Production diff: 2 additions and 1 deletion in
internal/jsonview/staticdisplay.go, plus one focused regression file.Full repository validation is left to the repository's GitHub Actions checks.
Risk
Low. The renderer already has the literal key names. The change only uses ordinary object-member lookup for those keys instead of reinterpreting them as query expressions. Objects with simple keys retain the same displayed values.