jsons

package
v0.0.0-...-b94c5f0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2017 License: MIT Imports: 4 Imported by: 0

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) Clone

func (j Array) Clone() Struct

Clone returns a deep copy of JSON array. It panics in case of error.

func (Array) Get

func (j Array) Get(path string) Struct

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

func (j Array) Indent() string

Indent returns indented JSON representation of JSON array. It panics in case of error.

func (Array) KeepFields

func (j Array) KeepFields(fields ...string) Struct

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

func (j Array) RemoveFields(fields ...string) Struct

RemoveFields returns a deep copy of JSON array with given object fields removed in all subobjects. It panics in case of error.

func (Array) String

func (j Array) String() string

String returns compact JSON representation of JSON array. It panics in case of error.

type Object

type Object map[string]interface{}

Object is JSON object structure. It implements Struct interface.

func (Object) Clone

func (j Object) Clone() Struct

Clone returns a deep copy of JSON object. It panics in case of error.

func (Object) Get

func (j Object) Get(path string) Struct

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

func (j Object) Indent() string

Indent returns indented JSON representation of JSON object. It panics in case of error.

func (Object) KeepFields

func (j Object) KeepFields(fields ...string) Struct

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

func (j Object) RemoveFields(fields ...string) Struct

RemoveFields returns a deep copy of JSON object with given fields removed. It panics in case of error.

func (Object) String

func (j Object) String() string

String returns compact JSON representation of JSON object. 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

func Parse(s string, args ...interface{}) Struct

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

func ParseBytes(b []byte) Struct

ParseBytes is a convenience function to Parse bytes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL