Skip to content

Commit b747cb6

Browse files
authored
Update sample code in readme
Update sample code in readme and add playground example link
1 parent 9a564b9 commit b747cb6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,24 @@ import "gopkg.in/thedevsaddam/gojsonq.v2"
2929

3030
Let's see a quick example:
3131

32+
[See in playground](https://play.golang.org/p/UiqyllP2vkn)
33+
3234
```go
3335
package main
3436

3537
import "github.com/thedevsaddam/gojsonq"
3638

37-
const json = `{"name":{"first":"Tom","last":"Hanks"},"age":61}`
38-
3939
func main() {
40+
const json = `{"name":{"first":"Tom","last":"Hanks"},"age":61}`
4041
name := gojsonq.New().JSONString(json).Find("name.first")
4142
println(name.(string)) // Tom
4243
}
43-
4444
```
4545

4646
Another example:
4747

48+
[See in playground](https://play.golang.org/p/QLVxpi6nVbi)
49+
4850
```go
4951
package main
5052

@@ -54,13 +56,11 @@ import (
5456
"github.com/thedevsaddam/gojsonq"
5557
)
5658

57-
const json = `{"city":"dhaka","type":"weekly","temperatures":[30,39.9,35.4,33.5,31.6,33.2,30.7]}`
58-
5959
func main() {
60+
const json = `{"city":"dhaka","type":"weekly","temperatures":[30,39.9,35.4,33.5,31.6,33.2,30.7]}`
6061
avg := gojsonq.New().JSONString(json).From("temperatures").Avg()
61-
fmt.Println(avg) // 33.471428571428575
62+
fmt.Printf("Average temperature: %.2f", avg) // 33.471428571428575
6263
}
63-
6464
```
6565

6666
You can query your document using the various query methods such as **[Find](https://github.com/thedevsaddam/gojsonq/wiki/Queries#findpath)**, **[First](https://github.com/thedevsaddam/gojsonq/wiki/Queries#first)**, **[Nth](https://github.com/thedevsaddam/gojsonq/wiki/Queries#nthindex)**, **[Pluck](https://github.com/thedevsaddam/gojsonq/wiki/Queries#pluckproperty)**, **[Where](https://github.com/thedevsaddam/gojsonq/wiki/Queries#wherekey-op-val)**, **[OrWhere](https://github.com/thedevsaddam/gojsonq/wiki/Queries#orwherekey-op-val)**, **[WhereIn](https://github.com/thedevsaddam/gojsonq/wiki/Queries#whereinkey-val)**, **[WhereStartsWith](https://github.com/thedevsaddam/gojsonq/wiki/Queries#wherestartswithkey-val)**, **[WhereEndsWith](https://github.com/thedevsaddam/gojsonq/wiki/Queries#whereendswithkey-val)**, **[WhereContains](https://github.com/thedevsaddam/gojsonq/wiki/Queries#wherecontainskey-val)**, **[Sort](https://github.com/thedevsaddam/gojsonq/wiki/Queries#sortorder)**, **[GroupBy](https://github.com/thedevsaddam/gojsonq/wiki/Queries#groupbyproperty)**, **[SortBy](https://github.com/thedevsaddam/gojsonq/wiki/Queries#sortbyproperty-order)** and so on. Also you can aggregate data after query using **[Avg](https://github.com/thedevsaddam/gojsonq/wiki/Queries#avgproperty)**, **[Count](https://github.com/thedevsaddam/gojsonq/wiki/Queries#count)**, **[Max](https://github.com/thedevsaddam/gojsonq/wiki/Queries#maxproperty)**, **[Min](https://github.com/thedevsaddam/gojsonq/wiki/Queries#minproperty)**, **[Sum](https://github.com/thedevsaddam/gojsonq/wiki/Queries#sumproperty)** etc.

0 commit comments

Comments
 (0)