Skip to content

feat(json): add --json-path to chart a nested array from a JSON envelope#143

Merged
fahimfaisaal merged 3 commits into
mainfrom
feat/json-path
Jun 21, 2026
Merged

feat(json): add --json-path to chart a nested array from a JSON envelope#143
fahimfaisaal merged 3 commits into
mainfrom
feat/json-path

Conversation

@fahimfaisaal

@fahimfaisaal fahimfaisaal commented Jun 21, 2026

Copy link
Copy Markdown
Member

What

Adds --json-path, a jq-like dot-path selector for the json parser. It pulls a
nested array out of a JSON envelope before parsing, so API payloads like
{"data":{"results":[...]}} or {"runs":[{"samples":[...]}]} chart directly —
no jq pre-processing step.

vizb api.json --json-path '.data.results'              # auto-detected as json
vizb api.json -P json --json-path '.runs[0].samples'   # array index then key
vizb api.json --json-path '.items[]'                   # trailing [] = the array itself

Why

The json parser 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
jq first. 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.
  • CLI wiring--json-path flag; auto-detect nudges to the json parser when
    a path is supplied (envelope files start with {); passthrough guard so an
    envelope object isn't mistaken for a vizb Dataset and silently emptied.
  • stdin fix — the piped-input reader dropped the final chunk when input had no
    trailing newline, truncating a single-line curl'd JSON body. Now written before
    the EOF break.
  • Docs--json-path guide section + flag row, and a landing-page Quick
    Example
    (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-json
    warn-and-ignore guard.
  • Full go test ./... + UI suite green via pre-commit hook.

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-commenter

codecov-commenter commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.44828% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/cli/pipeline.go 62.50% 10 Missing and 5 partials ⚠️
pkg/parser/json/jsonpath.go 86.48% 6 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@fahimfaisaal
fahimfaisaal merged commit 93707b0 into main Jun 21, 2026
1 check passed
@fahimfaisaal
fahimfaisaal deleted the feat/json-path branch June 21, 2026 10:36
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.

2 participants