// Uses the pointer to retrieve a value from a JSON document
769793
func (p *JsonPointer) Get(document interface{}) (interface{}, reflect.Kind, error) {

	is := &implStruct{mode: "GET", inDocument: document}
	p.implementation(is)
	return is.getOutNode, is.getOutKind, is.outError

}
1222356
func (c *Ctx) JSON(code int, i interface{}) (err error) {

	b, err := json.Marshal(i)
	if err != nil {
		return err
	}

	return c.JSONBytes(code, b)
}
195694
func (dec *Decoder) Object(value UnmarshalerJSONObject) error {
	initialKeysDone := dec.keysDone
	initialChild := dec.child
	dec.keysDone = 0
	dec.called = 0
	dec.child |= 1
	newCursor, err := dec.decodeObject(value)
	if err != nil {
		return err
	}
	dec.cursor = newCursor
	dec.keysDone = initialKeysDone
	dec.child = initialChild
	dec.called |= 1
	return nil
}
1344539
func (d *Document) MarshalJSON() ([]byte, error) {
	// we use the MarshalDoc type to avoid recursively calling this function below
	// when we marshal
	type MarshalDoc Document
	doc := MarshalDoc(*d)

	switch d.Mode {
	case ObjectMode:
		var data *Object
		if len(d.Data) > 0 {
			data = d.Data[0]
		}

		// subtype that overrides regular data List with a single Object for
		// fetch style request/responses
		type MarshalObject struct {
			MarshalDoc
			Data *Object `json:"data"`
		}

		return json.Marshal(MarshalObject{
			MarshalDoc: doc,
			Data:       data,
		})

	case ErrorMode:
		// subtype that omits data as expected for error responses. We cannot simply
		// use json:"-" for the data attribute otherwise it will not override the
		// default struct tag of it the composed MarshalDoc struct.
		type MarshalError struct {
			MarshalDoc
			Data *Object `json:"data,omitempty"`
		}

		return json.Marshal(MarshalError{
			MarshalDoc: doc,
		})

	case ListMode:
		return json.Marshal(doc)
	default:
		return nil, ISE(fmt.Sprintf("Unexpected DocumentMode value when marshaling: %d", d.Mode))
	}
}
1307092
func (e Event) Value(v interface{}) error {
	var tmp struct {
		Data interface{} `json:"data"`
	}
	tmp.Data = &v
	return json.Unmarshal(e.rawData, &tmp)
}
705870
func Get() (p []byte, err error) {
	var inf m.MemInfo
	err = inf.Get()
	if err != nil {
		return nil, err
	}
	return json.Marshal(&inf)
}
1255319
func GetJSONPathValue(obj interface{}, path string, allowMissingKeys bool) (interface{}, error) {
	j := jsonpath.New("GetJSONPathValue")
	// If the key is missing, return an empty string without errors
	j.AllowMissingKeys(allowMissingKeys)
	err := j.Parse(path)
	if err != nil {
		return "", errors.Wrapf(err, "JsonPath parse %s error", path)
	}
	values, err := j.FindResults(obj)
	if err != nil {
		return "", errors.Wrap(err, "JsonPath execute error")
	}
	if len(values) == 0 {
		return nil, nil
	}
	if len(values) > 1 {
		return nil, errors.Errorf("single result expected, got %d", len(values))
	}
	if values[0] == nil || len(values[0]) == 0 || values[0][0].IsNil() {
		return nil, nil
	}
	return values[0][0].Interface(), nil
}
1351743
func GetPointers(v reflect.Value) ([]uintptr, []uintptr, []uintptr) {
	pm := &pointerMap{
		allpointers:       []uintptr{},
		reusedPointers:    []uintptr{},
		primitivePointers: []uintptr{},
	}
	pm.getAllAndReusedPointers(v)
	pm.getPrimitivePointers(v)
	return pm.allpointers, pm.reusedPointers, pm.primitivePointers
}
355849
func SQLScanStrictJSON(obj interface{}, value interface{}) (err error) {
	switch val := value.(type) {
	case []byte:
		decoder := jsonex.NewDecoder(bytes.NewBuffer(val))
		decoder.DisallowUnknownFields()
		return decoder.Decode(obj)
	case nil:
		return nil
	default:
		return ErrorUnsupportedScanType1.New(nil, value)
	}
}
592062
func (al *HALLinks) UnmarshalJSON(j []byte) (err error) {
	var d linkField
	if err = json.Unmarshal(j, &d); err != nil {
		return
	}

	var u *url.URL
	for linkName, value := range d {
		if u, err = url.Parse(value["href"]); err != nil {
			break
		}
		al.Add(&HALLink{
			Name: linkName,
			URL:  u,
		})
	}
	return
}
532392
func (ctx *Context) JSON(obj interface{}) {
	json, err := json.Marshal(obj)
	if err != nil {
		panic(err)
	}
	ctx.SetHeader("Content-Type", "application/json")
	ctx.Send(json)
}
612666
func (p *JsonPointer) String() string {

	if len(p.referenceTokens) == 0 {
		return const_empty_pointer
	}

	pointerString := const_pointer_separator + strings.Join(p.referenceTokens, const_pointer_separator)

	return pointerString
}
277371
func (j *JSONPath) evalRecursive(input []reflect.Value, node *RecursiveNode) ([]reflect.Value, error) {
	result := []reflect.Value{}
	for _, value := range input {
		results := []reflect.Value{}
		value, isNil := template.Indirect(value)
		if isNil {
			continue
		}

		kind := value.Kind()
		if kind == reflect.Struct {
			for i := 0; i < value.NumField(); i++ {
				results = append(results, value.Field(i))
			}
		} else if kind == reflect.Map {
			for _, key := range value.MapKeys() {
				results = append(results, value.MapIndex(key))
			}
		} else if kind == reflect.Array || kind == reflect.Slice || kind == reflect.String {
			for i := 0; i < value.Len(); i++ {
				results = append(results, value.Index(i))
			}
		}
		if len(results) != 0 {
			result = append(result, value)
			output, err := j.evalRecursive(results, node)
			if err != nil {
				return result, err
			}
			result = append(result, output...)
		}
	}
	return result, nil
}
461738
func parse_json(data []rune) (Value, int, error) {
	var (
		cs int
		p int
		pe int = len(data)
		eof int = len(data)
	)
	var ret Value


//line ucl.go:1026
	{
	cs = document_start
	}

//line ucl.rl:279

//line ucl.go:1033
	{
	var _klen int
	var _trans int
	var _acts int
	var _nacts uint
	var _keys int
	if p == pe {
		goto _test_eof
	}
	if cs == 0 {
		goto _out
	}
_resume:
	_keys = int(_document_key_offsets[cs])
	_trans = int(_document_index_offsets[cs])

	_klen = int(_document_single_lengths[cs])
	if _klen > 0 {
		_lower := int(_keys)
		var _mid int
		_upper := int(_keys + _klen - 1)
		for {
			if _upper < _lower {
				break
			}

			_mid = _lower + ((_upper - _lower) >> 1)
			switch {
			case data[p] < _document_trans_keys[_mid]:
				_upper = _mid - 1
			case data[p] > _document_trans_keys[_mid]:
				_lower = _mid + 1
			default:
				_trans += int(_mid - int(_keys))
				goto _match
			}
		}
		_keys += _klen
		_trans += _klen
	}

	_klen = int(_document_range_lengths[cs])
	if _klen > 0 {
		_lower := int(_keys)
		var _mid int
		_upper := int(_keys + (_klen << 1) - 2)
		for {
			if _upper < _lower {
				break
			}

			_mid = _lower + (((_upper - _lower) >> 1) & ^1)
			switch {
			case data[p] < _document_trans_keys[_mid]:
				_upper = _mid - 2
			case data[p] > _document_trans_keys[_mid + 1]:
				_lower = _mid + 2
			default:
				_trans += int((_mid - int(_keys)) >> 1)
				goto _match
			}
		}
		_trans += _klen
	}

_match:
	cs = int(_document_trans_targs[_trans])

	if _document_trans_actions[_trans] == 0 {
		goto _again
	}

	_acts = int(_document_trans_actions[_trans])
	_nacts = uint(_document_actions[_acts]); _acts++
	for ; _nacts > 0; _nacts-- {
		_acts++
		switch _document_actions[_acts-1] {
		case 0:
//line ucl.rl:23

		return nil, -1, fmt.Errorf("parse error at byte %d (state=%d)", p, cs)
	
		case 1:
//line ucl.rl:245

		v, newp, err := parse_object(data, p, pe);
		if err != nil { return nil, -1, err };
		ret = v;
		p = ( newp) - 1

	
		case 2:
//line ucl.rl:252

		v, newp, err := parse_array(data, p, pe);
		if err != nil { return nil, -1, err };
		ret = v;
		p = ( newp) - 1

	
//line ucl.go:1134
		}
	}

_again:
	if cs == 0 {
		goto _out
	}
	p++
	if p != pe {
		goto _resume
	}
	_test_eof: {}
	if p == eof {
		__acts := _document_eof_actions[cs]
		__nacts := uint(_document_actions[__acts]); __acts++
		for ; __nacts > 0; __nacts-- {
			__acts++
			switch _document_actions[__acts-1] {
			case 0:
//line ucl.rl:23

		return nil, -1, fmt.Errorf("parse error at byte %d (state=%d)", p, cs)
	
//line ucl.go:1158
			}
		}
	}

	_out: {}
	}

//line ucl.rl:280

	return ret, -1, nil
}
1343727
func (v Value) MarshalJSON() ([]byte, error) {
	switch v.t {
	case reflect.String:
		return json.Marshal(v.s)
	case reflect.Int:
		return json.Marshal(v.i)
	case reflect.Bool:
		return json.Marshal(v.b)
	}

	return nil, fmt.Errorf("unknown value kind %v", v.t)
}
1353033
func Set(obj interface{}, pointer string, value interface{}) (err error) {
	defer func() {
		if e := recover(); e != nil {
			err = fmt.Errorf("invalid JSON pointer: %q: %v", pointer, e)
		}
	}()
	tokens, err := parse(pointer)
	if err != nil {
		return err
	}

	i := 0
	v := reflect.ValueOf(obj)
	var p reflect.Value
	var token string
	if len(tokens) > 0 && tokens[0] != "" {
		for i < len(tokens) {
			for v.Kind() == reflect.Interface {
				v = v.Elem()
			}
			p = v
			token = tokens[i]
			if n, err := strconv.Atoi(token); err == nil && isIndexed(v) {
				v = v.Index(n)
			} else {
				v = v.MapIndex(reflect.ValueOf(token))
			}
			i++
		}
		if p.Kind() == reflect.Map {
			p.SetMapIndex(reflect.ValueOf(token), reflect.ValueOf(value))
		} else {
			v.Set(reflect.ValueOf(value))
		}
		return nil
	}
	return fmt.Errorf("pointer should have element")
}
1188389
func NewJsonPointer(jsonPointerString string) (p JsonPointer, err error) {

	// Pointer to the root of the document
	if len(jsonPointerString) == 0 {
		// Keep referenceTokens nil
		return
	}
	if jsonPointerString[0] != '/' {
		return p, errors.New(const_invalid_start)
	}

	p.referenceTokens = strings.Split(jsonPointerString[1:], const_pointer_separator)
	return
}