Skip to content

Is a top-level array not supported ? #12

@Gys

Description

@Gys

Hi

I am trying to parse an array but cannot get is to work.
My test code below produces an error: Array index on non-array map[]
Is a first top-level array not supported ?

var jdata =[ { "elem1": { "id": 1 } }, { "elem2": { "id": 1 } } ]

func main() {
data := map[string]interface{}{}
dec := json.NewDecoder(strings.NewReader(jdata))
dec.Decode(&data)
jq := jsonq.NewQuery(data)
v, err := jq.Int("0", "elem1", "id")
if err != nil {
fmt.Printf("ERROR: %s\n", err)
return
}
fmt.Printf("%v\n", v)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions