From d498de1770df8f82df6a907f6a3df4107be97edd Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Sun, 21 Aug 2016 07:30:33 -0700 Subject: [PATCH] Update README.md --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index 379ba92..0b15e33 100644 --- a/README.md +++ b/README.md @@ -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