Skip to content

fix(jsonview): preserve literal object keys in pretty output and explorer - #143

Open
Ultron09 wants to merge 1 commit into
openai:mainfrom
Ultron09:fix/jsonview-literal-object-keys
Open

fix(jsonview): preserve literal object keys in pretty output and explorer#143
Ultron09 wants to merge 1 commit into
openai:mainfrom
Ultron09:fix/jsonview-literal-object-keys

Conversation

@Ultron09

Copy link
Copy Markdown

Summary

Preserve literal object keys across pretty formatting and the interactive JSON explorer instead of resolving member names containing dots or metacharacters as GJSON query paths.

Fixes #81.

Problem & Root Cause

The JSON renderer and explorer enumerate literal member names with @keys / gjson.Result.Get("@keys"), but subsequently fetched each value through result.Get(key.Str), data.Get(key.Str), or item.Get(key).

Because GJSON interprets string arguments to .Get() as path expressions (such as evaluating "a.b" as a traversal into nested object a -> b), keys with dots or other GJSON path syntax either:

  1. Display a nested child value under a top-level key's label, or
  2. Fail to find any value and display empty/null even when the literal key exists.

Fix

Materialize the object map once with result.Map() and look up values by exact literal key:

  • internal/jsonview/staticdisplay.go: formatJSONObject
  • internal/jsonview/explorer.go: newObjectTableView, newArrayOfObjectsTableView, TableView.loadMoreData, and formatObject

Regression Coverage

Added comprehensive regression tests in internal/jsonview/literal_keys_test.go:

  • TestStaticDisplayUsesLiteralObjectKeys: confirms static pretty formatting preserves top-level dotted keys and nested paths concurrently.
  • TestExploreTableUsesLiteralObjectKeys: confirms object table view and array-of-objects table view display the literal key's value.
  • TestExploreFormatObjectUsesLiteralObjectKeys: confirms object previews format literal keys correctly.

Validation Commands & Results

  • go test -v ./internal/jsonview/... (PASS)
  • go test ./pkg/cmd -run TestFormatJSON (PASS)
  • go vet ./internal/... ./pkg/... (PASS, clean)
  • go mod verify (PASS, all modules verified)
  • git diff --check (PASS, clean)

…orer

Resolve literal JSON object keys directly rather than interpreting them
as GJSON path expressions across static pretty formatting, interactive table
views, and object preview rendering.

Fixes openai#81
@Ultron09
Ultron09 requested a review from a team as a code owner August 31, 2026 08:25

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the affected renderer/explorer paths. @keys still supplies object/column order, while Map() is now only used for exact literal lookup, so dotted or metacharacter keys can't be reinterpreted as GJSON paths. columnKeys is also preserved for paged rows. The static, object-table and array-of-object regressions cover the main paths. Looks consistent.

@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:32:16.085764Z 2c55daf Manual request
🔒 Security Review Completed 2026-09-06T01:34:06.619740Z 2c55daf 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. 🎉

Reviewed commit: 2c55daf9ed

ℹ️ 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: 2c55daf9ed

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

3 participants