From b339e0f20ddcb9d027350751caf1530e32bcd9dc Mon Sep 17 00:00:00 2001 From: Mike Schinkel Date: Sat, 21 Jul 2018 02:28:25 -0400 Subject: [PATCH] Set index when loading maps. --- gjson.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gjson.go b/gjson.go index c08c87a..b7445cc 100644 --- a/gjson.go +++ b/gjson.go @@ -308,6 +308,7 @@ func (t Result) arrayOrMap(vc byte, valueize bool) (r arrayOrMapResult) { var value Result var count int var key Result + var index = 0 if vc == 0 { for ; i < len(json); i++ { if json[i] == '{' || json[i] == '[' { @@ -385,7 +386,9 @@ func (t Result) arrayOrMap(vc byte, valueize bool) (r arrayOrMapResult) { if valueize { r.oi[key.Str] = value.Value() } else { + value.Index = index r.o[key.Str] = value + index++ } } count++ @@ -393,7 +396,9 @@ func (t Result) arrayOrMap(vc byte, valueize bool) (r arrayOrMapResult) { if valueize { r.ai = append(r.ai, value.Value()) } else { + value.Index = index r.a = append(r.a, value) + index++ } } }