Documentation ¶
Overview ¶
Package jsons allows sloppy work with JSON structures (objects and arrays).
This package is tailored for usage in tests, specifically for Gophers tool. It sacrifices idiomatic approach for brevity and simplicity of usage. For example, all methods panic instead of returning error.
Usage of this package in non-testing code is highly unadvisable.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array []interface{}
Array is JSON array structure. It implements Struct interface.
func (Array) Get ¶
Get returns JSON substructure by given JSON Pointer path (https://tools.ietf.org/html/rfc6901). Scalar values are not supported. It panics in case of error.
func (Array) Indent ¶
Indent returns indented JSON representation of JSON array. It panics in case of error.
func (Array) KeepFields ¶
KeepFields returns a deep copy of JSON array with given object fields kept in all subobjects, and all other fields removed. It panics in case of error.
func (Array) RemoveFields ¶
RemoveFields returns a deep copy of JSON array with given object fields removed in all subobjects. It panics in case of error.
type Object ¶
type Object map[string]interface{}
Object is JSON object structure. It implements Struct interface.
func (Object) Get ¶
Get returns JSON substructure by given JSON Pointer path (https://tools.ietf.org/html/rfc6901). Scalar values are not supported. It panics in case of error.
func (Object) Indent ¶
Indent returns indented JSON representation of JSON object. It panics in case of error.
func (Object) KeepFields ¶
KeepFields returns a deep copy of JSON object with given fields kept, and all other fields removed. It panics in case of error.
func (Object) RemoveFields ¶
RemoveFields returns a deep copy of JSON object with given fields removed. It panics in case of error.
type Struct ¶
type Struct interface { // String returns compact JSON representation of JSON structure. // It panics in case of error. String() string // Indent returns indented JSON representation of JSON structure. // It panics in case of error. Indent() string // Get returns JSON substructure by given JSON Pointer path // (https://tools.ietf.org/html/rfc6901). Scalar values are not supported. // It panics in case of error. Get(path string) Struct // Clone returns a deep copy of JSON structure. // It panics in case of error. Clone() Struct // KeepFields returns a deep copy of JSON structure with given object fields kept, // and all other fields removed. // It panics in case of error. KeepFields(fields ...string) Struct // RemoveFields returns a deep copy of JSON structure with given object fields removed. // It panics in case of error. RemoveFields(fields ...string) Struct }
Struct is common interface for JSON structures.
func Cast ¶
func Cast(v interface{}) Struct
Cast makes type assertion for given value and retuns it as JSON structure. It supports Array / []interface{} and Object / map[string]interface{}. It panics for other types.
func Parse ¶
Parse makes JSON structure from given JSON string with fmt verbs and args. Scalar values are not supported. It panics in case of error.
func ParseBytes ¶
ParseBytes is a convenience function to Parse bytes.