/* Use "github.com/dustin/go-jsonpointer". Delayed parsing. */ func (this *parsedValue) Index(index int) (Value, bool) { if this.parsed != nil { return this.parsed.Index(index) } if this.parsedType != ARRAY { return missingIndex(index), false } if this.raw != nil { if index < 0 { return this.unwrap().Index(index) } res, err := jsonpointer.Find(this.raw, "/"+strconv.Itoa(index)) if err != nil { return missingIndex(index), false } if res != nil { return NewValue(res), true } } return missingIndex(index), false }
func TestJsonPointerInvalidJSON(t *testing.T) { bytes := []byte(`{"test":"value"`) val, err := jsonpointer.Find(bytes, "/test") if err != nil { t.Errorf("unexpected error %v", err) } if !reflect.DeepEqual(val, []byte(`"value"`)) { t.Errorf(`expected "value", got : %v`, string(val)) } }
/* Use "github.com/dustin/go-jsonpointer". Delayed parsing. */ func (this *parsedValue) Field(field string) (Value, bool) { if this.parsed != nil { return this.parsed.Field(field) } if this.parsedType != OBJECT { return missingField(field), false } res, err := jsonpointer.Find(this.raw, "/"+field) if err != nil { return missingField(field), false } if res != nil { return NewValue(res), true } return missingField(field), false }
func (this *parsedValue) Index(index int) (Value, error) { if this.parsed != nil { return this.parsed.Index(index) } if this.parsedType != ARRAY { return nil, Undefined(index) } if this.raw != nil { res, err := jsonpointer.Find(this.raw, "/"+strconv.Itoa(index)) if err != nil { return nil, err } if res != nil { return NewValueFromBytes(res), nil } } return nil, Undefined(index) }
func (this *parsedValue) Field(field string) (Value, error) { if this.parsed != nil { return this.parsed.Field(field) } if this.parsedType != OBJECT { return nil, Undefined(field) } if this.raw != nil { res, err := jsonpointer.Find(this.raw, "/"+field) if err != nil { return nil, err } if res != nil { return NewValueFromBytes(res), nil } } return nil, Undefined(field) }