Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
IamFaizanKhalid committed Aug 13, 2023
1 parent 80c27a0 commit 643dfd9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ go get -u github.com/IamFaizanKhalid/jsonq

## Usage Example

See [reference docs](https://pkg.go.dev/github.com/IamFaizanKhalid/jsonq) for more details.

```go
package main

Expand Down Expand Up @@ -47,21 +49,25 @@ func main() {
}
}`)

// parsing the JSON object
resp, err := jsonq.ParseObject(apiResponse)
if err != nil {
panic(err)
}

// getting values from the object
code := resp.Val("code").Int()
status := resp.Val("status").Str()

fmt.Println(code, status)

// checking if the object contains the sub-object
if !resp.Has("data") {
return
}
data := resp.Obj("data")

// getting a sub-object which is optional
userInfo, ok := data.OptObj("user")
if ok {
fmt.Println("-- User Info --")
Expand All @@ -73,6 +79,7 @@ func main() {

fmt.Println("-- Posts --")

// getting array of objects
posts := data.Arr("posts").Obj()

for _, post := range posts {
Expand Down

0 comments on commit 643dfd9

Please sign in to comment.