// Attempts to typecast the current value into an object.
// Returns error if the current value is not a json object.
// Example:
//		friendObject, err := friendValue.Object()
321102
func (v *Value) Object() (*Object, error) {

	var valid bool

	// Check the type of this data
	switch v.data.(type) {
	case map[string]interface{}:
		valid = true
		break
	}

	if valid {
		obj := new(Object)
		obj.valid = valid

		m := make(map[string]*Value)

		if valid {
			for key, element := range v.data.(map[string]interface{}) {
				m[key] = &Value{element, true}

			}
		}

		obj.data = v.data
		obj.m = m

		return obj, nil
	}

	return nil, ErrNotObject
}
1103871
func (e *ErrorObject) Error() string {
	err := fmt.Sprintf("%v error", e.Code)
	if e.Field != "" {
		err = fmt.Sprintf("%v caused by %v field", err, e.Field)
	}
	err = fmt.Sprintf("%v on %v resource", err, e.Resource)
	if e.Message != "" {
		err = fmt.Sprintf("%v: %v", err, e.Message)
	}

	return err
}
1092113
func (p *Parser) object() (ast.Node, error) {
	defer un(trace(p, "ParseType"))
	tok := p.scan()

	switch tok.Type {
	case token.NUMBER, token.FLOAT, token.BOOL, token.STRING, token.HEREDOC:
		return p.literalType()
	case token.LBRACE:
		return p.objectType()
	case token.LBRACK:
		return p.listType()
	case token.COMMENT:
		// implement comment
	case token.EOF:
		return nil, errEofToken
	}

	return nil, &PosError{
		Pos: tok.Pos,
		Err: fmt.Errorf("Unknown token: %+v", tok),
	}
}
1235713
func (v *Value) ObjectArray() ([]*Object, error) {

	var valid bool

	// Check the type of this data
	switch v.data.(type) {
	case []interface{}:
		valid = true
		break
	}

	// Unsure if this is a good way to use slices, it's probably not
	var slice []*Object

	if valid {

		for _, element := range v.data.([]interface{}) {
			childValue := Value{element, true}
			childObject, err := childValue.Object()

			if err != nil {
				return nil, ErrNotObjectArray
			}
			slice = append(slice, childObject)
		}

		return slice, nil
	}

	return nil, ErrNotObjectArray

}
1307092
func (e Event) Value(v interface{}) error {
	var tmp struct {
		Data interface{} `json:"data"`
	}
	tmp.Data = &v
	return json.Unmarshal(e.rawData, &tmp)
}
88251
func In(key string, obj *js.Object) (ok bool, err error) {
	if obj == nil || obj == js.Undefined || TypeOf(obj) != TypeObject {
		return false, errors.New("obj not a JavaScript object")
	}
	return js.Global.Get("$jsbuiltin$").Call("infunc", key, obj).Bool(), nil
}
398526
func (c *String) OnValueRemoteUpdate(fn func(string)) {
	c.OnValueUpdateFromConn(func(conn net.Conn, c *Characteristic, new, old interface{}) {
		fn(new.(string))
	})
}
978631
func (i *Item) ToObject(value interface{}) error {
	buffer := bytes.NewBuffer(i.Value)
	dec := gob.NewDecoder(buffer)
	return dec.Decode(value)
}
476416
func (r *Repository) Object(t plumbing.ObjectType, h plumbing.Hash) (object.Object, error) {
	obj, err := r.Storer.EncodedObject(t, h)
	if err != nil {
		return nil, err
	}

	return object.DecodeObject(r.Storer, obj)
}
589951
func SQLValueJSON(obj interface{}) (value driver.Value, err error) {
	if obj == nil {
		return
	}
	jsondata, err := jsonex.Marshal(obj)
	if err != nil {
		return
	}
	if bytes.Equal([]byte("{}"), jsondata) {
		return
	}
	return jsondata, nil
}
1043378
func (h *Handle) Value() []byte {
	b, err := json.Marshal(h)
	if err != nil {
		return nil
	}
	return b
}
514032
func objectMetaAndKind(typer runtime.ObjectTyper, obj runtime.Object) (*api.ObjectMeta, string, error) {
	objectMeta, err := api.ObjectMetaFor(obj)
	if err != nil {
		return nil, "", errors.NewInternalError(err)
	}
	_, kind, err := typer.ObjectVersionAndKind(obj)
	if err != nil {
		return nil, "", errors.NewInternalError(err)
	}
	return objectMeta, kind, nil
}
93592
func FromObject(obj runtime.Object) error {
	switch t := obj.(type) {
	case *unversioned.Status:
		return &StatusError{*t}
	}
	return &UnexpectedObjectError{obj}
}
1127856
func ObjectFromJSON(object interface{}, data string) error {
	jsonParser := json.NewDecoder(strings.NewReader(data))
	return jsonParser.Decode(object)
}
867889
func (c *Connection) Object(container string, objectName string) (info Object, headers Headers, err error) {
	err = withLORetry(0, func() (Headers, int64, error) {
		info, headers, err = c.objectBase(container, objectName)
		if err != nil {
			return headers, 0, err
		}
		return headers, info.Bytes, nil
	})
	return
}
848692
func (s *Scheme) ObjectKind(obj Object) (unversioned.GroupVersionKind, error) {
	gvks, err := s.ObjectKinds(obj)
	if err != nil {
		return unversioned.GroupVersionKind{}, err
	}
	return gvks[0], nil
}
808709
func TryToSliceValue(i interface{}, t reflect.Type) (slice reflect.Value, err error) {
	if s, ok := i.(string); ok {
		if s == "" {
			i = []string(nil)
		} else {
			i = strings.Split(s, ",")
		}
	}

	v := reflect.ValueOf(i)
	if v.Kind() != reflect.Slice {
		err = castError(i, "[]"+t.String())
		return
	}

	if t == v.Type().Elem() {
		return v, nil
	}

	length := v.Len()
	slice = reflect.MakeSlice(reflect.SliceOf(t), length, length)
	for k := 0; k < length; k++ {
		var value reflect.Value
		value, err = TryToValue(v.Index(k).Interface(), t)
		if err != nil {
			return
		}
		slice.Index(k).Set(value)
	}
	return slice, nil
}