Skip to content

Commit da3f5ee

Browse files
committed
fixed a bug introduced by last commit, added a test with nested data which have the target key after a nested object
1 parent 81562ce commit da3f5ee

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ func searchKeys(data []byte, keys ...string) int {
166166
case '{':
167167
level++
168168
case '}':
169-
if keyLevel > 0 {
169+
level--
170+
if level == keyLevel {
170171
keyLevel--
171172
}
172-
level--
173173
case '[':
174174
// Do not search for keys inside arrays
175175
if arraySkip := blockEnd(data[i:], '[', ']'); arraySkip == -1 {

parser_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ var getTests = []GetTest{
261261
path: []string{"a", "c"},
262262
isFound: false,
263263
},
264+
GetTest{
265+
desc: "handling nested json",
266+
json: `{"a":{"b":{"c":1},"d":4}}`,
267+
path: []string{"a", "d"},
268+
isFound: true,
269+
data: `4`,
270+
},
264271

265272
// Error/invalid tests
266273
GetTest{

0 commit comments

Comments
 (0)