mholt / json-to-go

Translates JSON into a Go type in your browser instantly (original)
https://mholt.github.io/json-to-go/
MIT License
4.48k stars 473 forks source link

Error when not using inline type definitions #111

Open bbkane opened 2 years ago

bbkane commented 2 years ago

JSON:

I have validated this JSON with jq.

{
  "data": [
    [
      "1",
      "2",
      "3"
    ],
    [
      "3",
      "4",
      "5"
    ]
  ],
  "columns": [
    {
      "title": "time"
    },
    {
      "title": "x"
    },
    {
      "title": "y"
    }
  ],
  "columnDefs": [
    {
      "className": "dt-center",
      "targets": "_all"
    }
  ],
  "pageLength": 50
}

Error: 2:13: expected ';', found '[' (and 1 more errors)

Oddly enough, when I check the Inline type definitions checkbox, I get the following (expected) output:

type AutoGenerated struct {
    Data    [][]string `json:"data"`
    Columns []struct {
        Title string `json:"title"`
    } `json:"columns"`
    ColumnDefs []struct {
        ClassName string `json:"className"`
        Targets   string `json:"targets"`
    } `json:"columnDefs"`
    PageLength int `json:"pageLength"`
}

Screenshot (note the JSON extends beyond the range of this screenshot):

image