tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
13.95k stars 841 forks source link

The array #310

Open flyrlabs-rch opened 1 year ago

flyrlabs-rch commented 1 year ago

this test fails because the length of value.Array() is two instead of the expected 4.

When the length was 1, the length of Array() was 1 When the length was 2, the length of Array() was 1 When the length was 3, the length of Array() was 1 When the length was 4, the length of Array() was 2 When the length was 5, the length of Array() was 3 When the length was 6, the length of Array() was 4

Might this be in arrayOrMap(), where it treats every other element as a key?

func TestArray(t *testing.T) {
    parsed := gjson.Get("{\"foo\" : [\"a\", Null, False, 1]}", "foo")

    assert.Truef(t, parsed.IsArray(), "the array element %v is not reporting IsArray()", parsed)
    assert.Equal(t, 4, len(parsed.Array()))
}

Cheers

tidwall commented 1 year ago

The json that you provided the Get statement looks invalid. The Null and False should be null and false.