Skip to content

feat(parser): add json parser support for 2d arrays#208

Merged
fahimfaisaal merged 5 commits into
goptics:mainfrom
hfl0506:feat/json-parser-support-for-2d-arrays
Jul 14, 2026
Merged

feat(parser): add json parser support for 2d arrays#208
fahimfaisaal merged 5 commits into
goptics:mainfrom
hfl0506:feat/json-parser-support-for-2d-arrays

Conversation

@hfl0506

@hfl0506 hfl0506 commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Added #202


Summary:

implemented JSON 2D array support in the tabular JSON
parser, reusing the existing CSV-style tabular pipeline for
grouping, select mode, and auto-value charts.


Change points:

  • Added first-element shape detection for top-level JSON arrays:

    • { keeps existing array-of-objects behavior.
    • [ enables matrix / 2D array parsing.
  • Added matrix header detection:

    • All-string first row becomes column headers.
    • Numeric-looking strings like "10" still count as headers.
  • Added synthetic column names for no-header matrices:

    • x, y, z, metric, then col5, col6, etc.
  • Matrix rows now normalize into the existing named-column row
    model.

  • Supported matrix cell rules:

    • JSON numbers and strings are accepted.
    • bool, null, nested arrays, and nested objects are skipped.
    • Ragged rows create gaps.
  • Preserved existing object-array behavior, including nested
    object flattening and skipped array-valued fields.

  • Added tests for:

    • Header matrix.
    • No-header 2-column auto-value.
    • No-header 4-column x/y/z + metric.
    • Mixed first row synthetic naming.
    • Numeric-looking string headers.
    • Ragged rows and skipped cells.
    • Empty/header-only arrays.
    • Nested matrix via --json-path.
  • Updated tabular JSON docs and parser docs.

  • Added changelog entry.


Test Result

Case 1

# commands
env GOCACHE=/private/tmp/vizb-go-build go test ./pkg/parser/json
env GOCACHE=/private/tmp/vizb-go-build go test ./pkg/parser/...

# result
ok      github.com/goptics/vizb/pkg/parser/json (cached)
ok      github.com/goptics/vizb/pkg/parser      (cached)
ok      github.com/goptics/vizb/pkg/parser/csv  (cached)
ok      github.com/goptics/vizb/pkg/parser/golang       (cached)
ok      github.com/goptics/vizb/pkg/parser/javascript   (cached)
ok      github.com/goptics/vizb/pkg/parser/json (cached)
ok      github.com/goptics/vizb/pkg/parser/rust (cached)

Case 2

# command
printf '[["region","sales"],["West",10],["East",20]]' > /tmp/header-matrix.json
./bin/vizb /tmp/header-matrix.json -P json -o /tmp/header-matrix.out.json
cat /tmp/header-matrix.out.json | jq
# result
{
  "timestamp": "2026-07-12T22:33:10Z",
  "name": "Comparisons",
  "theme": "default",
  "axes": [
    {
      "key": "x",                                                         
     "label": "region"
    }
  ],
  "settings": [
    {
      "type": "bar",
      "scale": "linear"
    },
    {
      "type": "line",
      "scale": "linear"
    },
    {
      "type": "pie"
    }
  ],
  "data": [
    {
      "xAxis": "West",
      "stats": [
        {
          "type": "sales",
          "value": 10
        }
      ]
    },
    {
      "xAxis": "East",
      "stats": [
        {                                                                     
          "type": "sales",
          "value": 20                                                       
        }
      ]                                                                 
    }
  ]                                                                 
}

Case 3

# commands
printf '[[1,2],[3,4],[5,6]]' > /tmp/xy-matrix.json
./bin/vizb scatter /tmp/xy-matrix.json -P json -o /tmp/xy-matrix.out.json
cat /tmp/xy-matrix.out.json | jq
# result
{
  "timestamp": "2026-07-12T22:39:56Z",
  "name": "Comparisons",
  "theme": "default",
  "axes": [
    {
      "key": "x",
      "label": "x",
      "type": "value"
    },                                                                  
  {
      "key": "y",
      "label": "y",                                                       
      "type": "value"
    }
  ],
  "settings": [
    {
      "type": "scatter",
      "scale": "linear"
    }
  ],
  "data": [
    {                                                                     
      "xAxis": "1",
      "yAxis": "2"
    },
    {
      "xAxis": "3",
      "yAxis": "4"
    },
    {
      "xAxis": "5",
      "yAxis": "6"
    }
  ],
  "preserveRows": true
}

Case 4

# commands
printf '[[1,2,3,4],[5,6,7,8]]' > /tmp/xyz-metric.json
./bin/vizb scatter /tmp/xyz-metric.json -P json -o /tmp/xyz-metric.out.json
cat /tmp/xyz-metric.out.json | jq
# result
{
  "timestamp": "2026-07-12T22:41:17Z",
  "name": "Comparisons",
  "theme": "default",
  "axes": [
    {
      "key": "x",
      "label": "x",
      "type": "value"                                                   
    },
    {
      "key": "y",                                                         
      "label": "y",
      "type": "value"
    },
    {
      "key": "z",
      "label": "z",
      "type": "value"
    },
    {
      "key": "metric",
      "label": "metric",                                                  
      "type": "value"
    }
  ],
  "settings": [
    {
      "type": "scatter",
      "scale": "linear",
      "threeD": true,
      "threeDVisualMap": true
    }
  ],
  "data": [                                                             {
      "xAxis": "1",
      "yAxis": "2",
      "zAxis": "3",
      "metric": "4"
    },
    {
      "xAxis": "5",
      "yAxis": "6",
      "zAxis": "7",
      "metric": "8"
    }
  ],
  "preserveRows": true
}

Case 5

# HTML smoke test
# command
./bin/vizb scatter /tmp/xy-matrix.json -P json -o /tmp/xy-matrix.html
open /tmp/xy-matrix.html
Screenshot 2026-07-12 at 3 42 46 PM

Case 6

# 4 column case 
# z + metric
# command
printf '[[1,2,3,4],[5,6,7,8]]' > /tmp/xyz-metric.json
./bin/vizb scatter /tmp/xyz-metric.json -P json -o /tmp/xyz-metric.html
open /tmp/xyz-metric.html
Screenshot 2026-07-12 at 3 44 06 PM

@codecov-commenter

codecov-commenter commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@hfl0506
hfl0506 marked this pull request as ready for review July 12, 2026 23:05
@hfl0506

hfl0506 commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

Hi @fahimfaisaal Can I get you review when you have a moment ? Thank you :)

@fahimfaisaal

Copy link
Copy Markdown
Member

Hi @hfl0506 Thanks for the PR; I will review it soon. Meanwhile, you can check out other issues if you are interested in them

@fahimfaisaal fahimfaisaal added enhancement New feature or request cli Command line interface related tasks parser Parser-related tasks labels Jul 13, 2026
@fahimfaisaal fahimfaisaal changed the title feat(parser)/add json parser support for 2d arrays feat(parser): add json parser support for 2d arrays Jul 13, 2026

@fahimfaisaal fahimfaisaal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, except the irrelevant changelog update

Comment thread CHANGELOG.md Outdated
@fahimfaisaal
fahimfaisaal merged commit 487ab43 into goptics:main Jul 14, 2026
11 checks passed
@fahimfaisaal fahimfaisaal added this to the Release v0.16.0 milestone Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Command line interface related tasks enhancement New feature or request parser Parser-related tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat]: JSON parser support for 2D arrays (header row + auto-value)

3 participants