Fix different reuslts on duplicate keys

fixes #79
This commit is contained in:
Josh Baker 2018-07-30 14:44:31 -07:00
parent ba784d767a
commit f92dbfc6b2
2 changed files with 21 additions and 2 deletions

View File

@ -383,11 +383,15 @@ func (t Result) arrayOrMap(vc byte, valueize bool) (r arrayOrMapResult) {
key = value key = value
} else { } else {
if valueize { if valueize {
if _, ok := r.oi[key.Str]; !ok {
r.oi[key.Str] = value.Value() r.oi[key.Str] = value.Value()
}
} else { } else {
if _, ok := r.o[key.Str]; !ok {
r.o[key.Str] = value r.o[key.Str] = value
} }
} }
}
count++ count++
} else { } else {
if valueize { if valueize {

View File

@ -1391,3 +1391,18 @@ func TestNumFloatString(t *testing.T) {
t.Fatalf("expected '%v', got '%v'", "-9007199254740993", res.String()) t.Fatalf("expected '%v', got '%v'", "-9007199254740993", res.String())
} }
} }
func TestDuplicateKeys(t *testing.T) {
// this is vaild json according to the JSON spec
var json = `{"name": "Alex","name": "Peter"}`
if Parse(json).Get("name").String() !=
Parse(json).Map()["name"].String() {
t.Fatalf("expected '%v', got '%v'",
Parse(json).Get("name").String(),
Parse(json).Map()["name"].String(),
)
}
if !Valid(json) {
t.Fatal("should be valid")
}
}