gjson
gjson copied to clipboard
The array
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
The json that you provided the Get statement looks invalid. The Null and False should be null and false.