We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Such an error was found when executing the program.
./hello.go:47:79: multiple-value jsonParsed.Search("employees", "address").ChildrenMap() in single-value context
And the result is empty. fmt.Println("ID of first employee:\t", jsonParsed.Path("employees.employee.0.id").String())
fmt.Println("ID of first employee:\t", jsonParsed.Path("employees.employee.0.id").String())
Here is my code
package main import ( "fmt" "github.com/Jeffail/gabs" ) func main() { data := []byte(`{ "employees":{ "protected":false, "address":{ "street":"22 Saint-Lazare", "postalCode":"75003", "city":"Paris", "countryCode":"FRA", "country":"France" }, "employee":[ { "id":1, "first_name":"Jeanette", "last_name":"Penddreth" }, { "id":2, "firstName":"Giavani", "lastName":"Frediani" } ] } }`) jsonParsed, err := gabs.ParseJSON(data) if err != nil { panic(err) } // Search JSON fmt.Println("Get value of Protected:\t", jsonParsed.Path("employees.protected").Data()) fmt.Println("Get value of Country:\t", jsonParsed.Search("employees", "address", "country").Data()) fmt.Println("ID of first employee:\t", jsonParsed.Search("employees", "employee", "id").String()) fmt.Println("Check Country Exists:\t", jsonParsed.Exists("employees", "address", "countryCode")) // Iterating address objects for key, child := range jsonParsed.Search("employees", "address").ChildrenMap() { fmt.Printf("Key=>%v, Value=>%v\n", key, child.Data().(string)) } // // Iterating employee array // for _, child := range jsonParsed.Search("employees", "employee").Children() { // fmt.Println(child.Data()) // } // // Use index in your search // for _, child := range jsonParsed.Search("employees", "employee", "0").Children() { // fmt.Println(child.Data()) // } }
The text was updated successfully, but these errors were encountered:
I found the same issue and fixed by using github.com/Jeffail/gabs/v2 instead of github.com/Jeffail/gabs You may also need to check your go.mod
github.com/Jeffail/gabs/v2
github.com/Jeffail/gabs
go.mod
Sorry, something went wrong.
No branches or pull requests
Such an error was found when executing the program.
And the result is empty.
fmt.Println("ID of first employee:\t", jsonParsed.Path("employees.employee.0.id").String())
Here is my code
The text was updated successfully, but these errors were encountered: