Skip to content

Commit

Permalink
add instruction as using as a library (ref: #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Dec 22, 2019
1 parent 0e0be4b commit d703a8c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Pure Go implementation of [jq](https://github.com/stedolan/jq).

## Usage
### from command line
```sh
$ echo '{"foo": 128}' | gojq '.foo'
128
Expand Down Expand Up @@ -42,6 +43,37 @@ gojq: invalid json: <stdin>
^ invalid character 'b' looking for beginning of object key string
```
### as a library
```go
package main

import (
"fmt"
"log"

"github.com/itchyny/gojq"
)

func main() {
query, err := gojq.Parse(".foo | ..")
if err != nil {
log.Fatalf("%s\n", err)
}
input := map[string]interface{}{"foo": []interface{}{1, 2, 3}}
iter := query.Run(input)
for {
v, ok := iter.Next()
if !ok {
break
}
if err, ok := v.(error); ok {
log.Fatalf("%s\n", err)
}
fmt.Printf("%#v\n", v)
}
}
```
## Installation
### Homebrew
```sh
Expand Down

0 comments on commit d703a8c

Please sign in to comment.