https://github.com/linkdata/jq
Go JSON structure query path getter/setter
https://github.com/linkdata/jq
golang json nodependencies
Last synced: about 1 month ago
JSON representation
Go JSON structure query path getter/setter
- Host: GitHub
- URL: https://github.com/linkdata/jq
- Owner: linkdata
- License: mit
- Created: 2025-08-12T06:33:21.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-08-20T13:32:47.000Z (7 months ago)
- Last Synced: 2025-08-20T14:30:39.806Z (7 months ago)
- Topics: golang, json, nodependencies
- Language: Go
- Homepage:
- Size: 42 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/linkdata/jq/actions/workflows/build.yml)
[](https://html-preview.github.io/?url=https://github.com/linkdata/jq/blob/coverage/main/report.html)
[](https://goreportcard.com/report/github.com/linkdata/jq)
[](https://godoc.org/github.com/linkdata/jq)
# jq
Go JSON structure query path getter/setter
```go
package main
import (
"encoding/json"
"fmt"
"github.com/linkdata/jq"
)
const rawJson = `{
"name": "John Doe",
"age": 30,
"isStudent": false,
"hobbies": ["reading", "hiking", "gaming"],
"address": {
"street": "123 Main St",
"city": "Anytown",
"zip": "12345"
}
}`
type Address struct {
Street string `json:"street"`
City string `json:"city"`
Zip string `json:"zip"`
}
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
IsStudent bool `json:"isStudent"`
Hobbies []string `json:"hobbies"`
Address Address `json:"address"`
}
func main() {
var person Person
var err error
if err = json.Unmarshal([]byte(rawJson), &person); err == nil {
var firsthobby string
if firsthobby, err = jq.GetAs[string](&person, "hobbies.0"); err == nil {
fmt.Println(firsthobby)
var address Address
if address, err = jq.GetAs[Address](&person, "address"); err == nil {
fmt.Println(address.City)
}
}
}
if err != nil {
panic(err)
}
// Output:
// reading
// Anytown
}
```