Skip to content

fix(jsonview): preserve literal object keys in pretty output - #86

Open
sylvesterkaczmarek wants to merge 2 commits into
openai:mainfrom
sylvesterkaczmarek:fix/pretty-literal-object-keys
Open

fix(jsonview): preserve literal object keys in pretty output#86
sylvesterkaczmarek wants to merge 2 commits into
openai:mainfrom
sylvesterkaczmarek:fix/pretty-literal-object-keys

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

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 through result.Get(key.Str).

Result.Get does 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 resolves result.Get("a.b") to the nested a.b value. 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:

  • @keys returns literal object member names;
  • Result.Get treats 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:

values := result.Map()

and then index it with the enumerated key:

value := values[key.Str]

This also avoids repeatedly reparsing each key as a path.

Regression coverage

Added a focused regression with both:

  • a top-level key named "a.b" whose value is "literal-value";
  • a nested a -> b value 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 main at d082a010f7c6cacf407d8a1581446a7857f9f1bb and 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.

@markstuart-oai

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-06T01:31:36.289279Z a3d4e7b Manual request
🔒 Security Review Completed 2026-09-06T01:32:59.633596Z a3d4e7b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: a3d4e7b9f3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: a3d4e7b9f3

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pretty JSON output resolves literal object keys as GJSON paths

2 participants