feat(json): add --json-path to chart a nested array from a JSON envelope#143
Merged
Conversation
The json parser only accepted a top-level array of objects, so real-world
API payloads wrapped in an envelope (e.g. {"data":{"results":[...]}}) had to
be pre-processed with jq. Add --json-path, a jq-like dot-path selector
(.a.b[0].c, trailing [] sugar) that extracts the nested array before parsing.
- registry: JSONPath field on parser.Config
- cli: --json-path flag, auto-detect nudge to the json parser, passthrough
guard so an envelope object isn't mistaken for a vizb Dataset
- pkg/parser/json: SelectPath navigator (stdlib only, no new dependency)
- pipeline: fix stdin reader dropping the final newline-less chunk, so a
single-line curl'd JSON payload is no longer truncated
- docs: --json-path section + flag row, and a Quick Example showcasing a
GitHub contribution history rendered in 3D
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
What
Adds
--json-path, a jq-like dot-path selector for thejsonparser. It pulls anested array out of a JSON envelope before parsing, so API payloads like
{"data":{"results":[...]}}or{"runs":[{"samples":[...]}]}chart directly —no
jqpre-processing step.Why
The
jsonparser only accepted a top-level array of objects. Real-world JSON(especially public APIs) wraps rows in an envelope, forcing users to shell out to
jqfirst. This makes vizb consume that data in one pipe.How
parser.Config.JSONPath— new optional field (zero value = current behavior).pkg/parser/json/SelectPath— dot-path navigator: object keys (.a.b),array indices (
[n]), optional leading., trailing[]sugar. Stdlib only,no new dependency. Array → as-is; single object → 1-element array; scalar → error.
--json-pathflag; auto-detect nudges to thejsonparser whena path is supplied (envelope files start with
{); passthrough guard so anenvelope object isn't mistaken for a vizb Dataset and silently emptied.
trailing newline, truncating a single-line
curl'd JSON body. Now written beforethe EOF break.
--json-pathguide section + flag row, and a landing-page QuickExample (bash + PowerShell) rendering a GitHub contribution history in 3D.
Tests
pkg/parser/json/jsonpath_test.go— 10-case table: nested keys, index,[],single-object wrap, and error paths (missing key, OOB, scalar, wrong-type step).
cmd/cli/pipeline_test.go— envelope extraction → parse, and the non-jsonwarn-and-ignore guard.
go test ./...+ UI suite green via pre-commit hook.