thedevsaddam / gojsonq

A simple Go package for querying over JSON, YAML, XML, and CSV data.
https://github.com/thedevsaddam/gojsonq/wiki
MIT License
2.19k stars 140 forks source link

Empty result in "SELECT" #92

Closed cryptomatictrader closed 2 years ago

cryptomatictrader commented 2 years ago

I get empty result in the following code but it works fine if I use "FIND" instead of "SELECT". Any idea why?

See this in Go Playground

package main

import (
    "fmt"
    gojsonq "github.com/thedevsaddam/gojsonq/v2"
)

func main() {
    const json = `{"name":{"first":"Tom","last":"Hanks"},"age":61}`
    jq := gojsonq.New().FromString(json).Select("name")
    fmt.Printf("%#v\n", jq.Get())
}
thedevsaddam commented 2 years ago

While using Get please use From method to select a start point

    const json = `{"name":{"first":"Tom","last":"Hanks"},"age":61}`
    jq := gojsonq.New().FromString(json)
    fmt.Printf("%#v\n", jq.From("name").Get())