internal

package
v0.0.0-...-d070082 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	// Type is the json type
	Type Type
	// Raw is the raw json
	Raw string
	// Str is the json string
	Str string
	// Num is the json number
	Num float64
	// Index of raw value in original json, zero means index unknown
	Index int
}

Result represents a json value that is returned from Parse().

func Parse

func Parse(json string) (Result, error)

Parse parses the json and returns a result.

func ParseBytes

func ParseBytes(json []byte) (Result, error)

ParseBytes parses the json and returns a result. If working with bytes, this method preferred over Parse(string(data))

func ParseLines

func ParseLines(json string) []Result

ParseLines iterates through lines of JSON as specified by the JSON Lines format (http://jsonlines.org/). Each line is returned as a GJSON Result.

func (Result) Array

func (t Result) Array() []Result

Array returns back an array of values. If the result represents a non-existent value, then an empty array will be returned. If the result is not a JSON array, the return value will be an array containing one result.

func (Result) Bool

func (t Result) Bool() bool

Bool returns an boolean representation.

func (Result) Exists

func (t Result) Exists() bool

Exists returns true if value exists.

 if gjson.Get(json, "name.last").Exists(){
		println("value exists")
 }

func (Result) FirstKey

func (t Result) FirstKey(key string) bool

func (Result) Float

func (t Result) Float() float64

Float returns an float64 representation.

func (Result) ForEach

func (t Result) ForEach(iterator func(key, value Result) bool)

ForEach iterates through values. If the result represents a non-existent value, then no values will be iterated. If the result is an Object, the iterator will pass the key and value of each item. If the result is an Array, the iterator will only pass the value of each item. If the result is not a JSON array or object, the iterator will pass back one value equal to the result.

func (Result) Int

func (t Result) Int() int64

Int returns an integer representation.

func (Result) IsArray

func (t Result) IsArray() bool

IsArray returns true if the result value is a JSON array.

func (Result) IsObject

func (t Result) IsObject() bool

IsObject returns true if the result value is a JSON object.

func (Result) Lookup

func (t Result) Lookup(key string) Result

Lookup iterates through the document looking for a matching key

func (Result) Map

func (t Result) Map() map[string]Result

Map returns back an map of values. The result should be a JSON array.

func (Result) String

func (t Result) String() string

String returns a string representation of the value.

func (Result) Time

func (t Result) Time() time.Time

Time returns a time.Time representation.

func (Result) Uint

func (t Result) Uint() uint64

Uint returns an unsigned integer representation.

func (Result) Value

func (t Result) Value() interface{}

Value returns one of these types:

bool, for JSON booleans
float64, for JSON numbers
Number, for JSON numbers
string, for JSON string literals
nil, for JSON null
map[string]interface{}, for JSON objects
[]interface{}, for JSON arrays

type Type

type Type int

Type is Result type

const (
	// Null is a null json value
	Null Type = iota
	// False is a json false boolean
	False
	// Number is json number
	Number
	// String is a json string
	String
	// True is a json true boolean
	True
	// JSON is a raw block of JSON
	JSON
)

func (Type) String

func (t Type) String() string

String returns a string representation of the type.

Jump to

Keyboard shortcuts

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