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.

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