From e14b8d37087f5774d3d4dce0b0b708cbc32015f7 Mon Sep 17 00:00:00 2001 From: tidwall Date: Mon, 21 Nov 2022 18:54:56 -0700 Subject: [PATCH] Add test --- gjson_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gjson_test.go b/gjson_test.go index c91a2d8..77f6ce9 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -2573,3 +2573,21 @@ func TestDeepModifierWithOptions(t *testing.T) { actual + "\n\t<<< MISMATCH >>>") } } + +func TestIssue301(t *testing.T) { + json := `{ + "children": ["Sara","Alex","Jack"], + "fav.movie": ["Deer Hunter"] + }` + + assert(t, Get(json, `children.0`).String() == "Sara") + assert(t, Get(json, `children.[0]`).String() == `["Sara"]`) + assert(t, Get(json, `children.1`).String() == "Alex") + assert(t, Get(json, `children.[1]`).String() == `["Alex"]`) + assert(t, Get(json, `children.[10]`).String() == `[]`) + assert(t, Get(json, `fav\.movie.0`).String() == "Deer Hunter") + assert(t, Get(json, `fav\.movie.[0]`).String() == `["Deer Hunter"]`) + assert(t, Get(json, `fav\.movie.1`).String() == "") + assert(t, Get(json, `fav\.movie.[1]`).String() == "[]") + +}