From 56c0a0aa5b8ff73f36eab8cd0fa30465cea393d1 Mon Sep 17 00:00:00 2001 From: tidwall Date: Tue, 22 Mar 2022 09:30:19 -0700 Subject: [PATCH] Update comment --- gjson.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/gjson.go b/gjson.go index f863689..06ebcf8 100644 --- a/gjson.go +++ b/gjson.go @@ -3147,6 +3147,20 @@ func revSquash(json string) string { return json } +// Paths returns the original GJSON paths for a Result where the Result came +// from a simple query path that returns an array, like: +// +// gjson.Get(json, "friends.#.first") +// +// The returned value will be in the form of a JSON array: +// +// ["friends.0.first","friends.1.first","friends.2.first"] +// +// The param 'json' must be the original JSON used when calling Get. +// +// Returns an empty string if the paths cannot be determined, which can happen +// when the Result came from a path that contained a multipath, modifier, +// or a nested query. func (t Result) Paths(json string) []string { if t.Indexes == nil { return nil @@ -3162,8 +3176,20 @@ func (t Result) Paths(json string) []string { return paths } -// Path returns the original GJSON path for Result. -// The json param must be the original JSON used when calling Get. +// Path returns the original GJSON path for a Result where the Result came +// from a simple path that returns a single value, like: +// +// gjson.Get(json, "friends.#(last=Murphy)") +// +// The returned value will be in the form of a JSON string: +// +// "friends.0" +// +// The param 'json' must be the original JSON used when calling Get. +// +// Returns an empty string if the paths cannot be determined, which can happen +// when the Result came from a path that contained a multipath, modifier, +// or a nested query. func (t Result) Path(json string) string { var path []byte var comps []string // raw components