Update README.md

This commit is contained in:
Josh Baker 2016-08-21 07:30:33 -07:00 committed by GitHub
parent cec0cb946f
commit d498de1770
1 changed files with 31 additions and 0 deletions

View File

@ -108,6 +108,37 @@ result.Type // can be String, Number, True, False, Null, or JSON
result.Str // holds the string
result.Num // holds the float64 number
result.Raw // holds the raw json
result.Multi // holds nested array values
```
## Get nested array values
Suppose you want all the last names from the following json:
```json
{
"programmers": [
{
"firstName": "Janet",
"lastName": "McLaughlin",
}, {
"firstName": "Elliotte",
"lastName": "Hunter",
}, {
"firstName": "Jason",
"lastName": "Harold",
}
]
}`
```
You would use the path "programmers.#.lastName" like such:
```go
result := gjson.Get(json, "programmers.#.lastName")
for _,name := range result.Multi {
println(name.String())
}
```
## Check for the existence of a value