Documentation
¶
Overview ¶
Package nosj provides lightweight JSON reflection for testing.
Index ¶
- Constants
- type JSON
- func (j JSON) BoolValue() bool
- func (j JSON) F(key string) JSON
- func (j JSON) GetByPointer(p string) (nosj JSON, err error)
- func (j JSON) GetField(key string) JSON
- func (j JSON) HasKey(key string) bool
- func (j JSON) HasPointer(p string) (bool, error)
- func (j JSON) IsBool() bool
- func (j JSON) IsList() bool
- func (j JSON) IsNull() bool
- func (j JSON) IsNum() bool
- func (j JSON) IsOb() bool
- func (j JSON) IsOfType(typ string) bool
- func (j JSON) IsString() bool
- func (j JSON) ListValue() (list []JSON)
- func (j JSON) NumValue() float64
- func (j JSON) ObValue() map[string]interface{}
- func (j JSON) RawValue() interface{}
- func (j JSON) SetElem(index int, value interface{}) error
- func (j JSON) SetField(fieldName string, val interface{})
- func (j JSON) StringValue() string
Constants ¶
const ( JSONString = "string" JSONNum = "number" JSONOb = "object" JSONList = "list" JSONNull = "null" JSONBool = "bool" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
JSON represents a parsed json structure.
func ParseJSON ¶
ParseJSON unmarshals yaml from an input string. Use this for generating a JSON struct, whose contents you can examine using the following functions.
func ParseYAML ¶
ParseYAML unmarshals json from an input string. Use this for generating a YAML struct, whose contents you can examine using the following functions.
func (JSON) BoolValue ¶
BoolValue returns the golang bool representation of the json bool represented by this JSON struct. If the JSON struct does not represent a json bool, this method panics. If in doubt, check with `IsBool()`
func (JSON) GetByPointer ¶
GetByPointer returns a JSON struct containing the contents of the original json at the given pointer address `p`. For more information on json pointers, see https://tools.ietf.org/html/rfc6901
func (JSON) GetField ¶
GetField returns a JSON struct containing the contents of the original json at the given `key`. If this method name feels too long, use `F(key)`.
Note: this function panics if the given `key` does not exist. If in doubt, check with `HasKey()`.
func (JSON) HasKey ¶
HasKey returns true iff the json object represented by this JSON struct contains `key`
Note: this will panic if the json represented by this JSON struct is not a json object. If in doubt, check with `IsOb()`
func (JSON) HasPointer ¶
HasPointer returns true iff the json object represented by this JSON struct contains the pointer `p`
For more information on json pointers, see https://tools.ietf.org/html/rfc6901
func (JSON) IsList ¶
IsList returns true iff the json represented by this JSON struct is a json list.
func (JSON) IsOfType ¶
IsOfType returns true iff the JSON struct represents a json of type `typ`. Valid values of `typ` are listed as constants above.
func (JSON) IsString ¶
IsString returns true iff the json represented by this JSON struct is a string.
func (JSON) ListValue ¶
ListValue returns a golang slice of JSON structs representing the json list represented by this JSON struct. If the JSON struct does not represent a json list, this method panics. If in doubt, check with `IsList()`
func (JSON) NumValue ¶
NumValue returns the golang float64 representation of the json number represented by this JSON struct. If the JSON struct does not represent a json number, this method panics. If in doubt, check with `IsNum()`
func (JSON) ObValue ¶
ObValue returns a golang map[string]interface{} represenation of the json object represented by this JSON struct. If the JSON struct does not represent a json object, this method panics. If in doubt, check with `IsOb()`
func (JSON) RawValue ¶
func (j JSON) RawValue() interface{}
RawValue returns the raw go value of the parsed json, without any type checking
func (JSON) SetElem ¶
SetElem sets the element at a given index in this JSON list to the given value. If this JSON object does not represent a list, return an error
func (JSON) SetField ¶
SetField updates the field `fieldName` of this JSON object. If this is not a JSON object, we might crash. If the field `fieldName` does not exist on this object, create it.
func (JSON) StringValue ¶
StringValue returns the golang string representation of the json string represented by this JSON struct. If the JSON struct does not represent a json string, this method panics. If in doubt, check with `IsString()`
Directories
¶
Path | Synopsis |
---|---|
Package gnosj provides gomega matchers for using nosj with the ginkgo and gomega testing libraries: https://github.com/onsi/gomega https://github.com/onsi/ginkgo
|
Package gnosj provides gomega matchers for using nosj with the ginkgo and gomega testing libraries: https://github.com/onsi/gomega https://github.com/onsi/ginkgo |