fix(jsonview): preserve literal object keys in pretty output and explorer - #143
Open
Ultron09 wants to merge 1 commit into
Open
fix(jsonview): preserve literal object keys in pretty output and explorer#143Ultron09 wants to merge 1 commit into
Ultron09 wants to merge 1 commit into
Conversation
…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
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
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.
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
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 throughresult.Get(key.Str),data.Get(key.Str), oritem.Get(key).Because GJSON interprets string arguments to
.Get()as path expressions (such as evaluating"a.b"as a traversal into nested objecta -> b), keys with dots or other GJSON path syntax either:Fix
Materialize the object map once with
result.Map()and look up values by exact literal key:internal/jsonview/staticdisplay.go:formatJSONObjectinternal/jsonview/explorer.go:newObjectTableView,newArrayOfObjectsTableView,TableView.loadMoreData, andformatObjectRegression 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)