fix(jsonview): preserve literal object keys in pretty output - #86
fix(jsonview): preserve literal object keys in pretty output#86sylvesterkaczmarek wants to merge 2 commits into
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
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.