package jsonparser
Import Path
github.com/buger/jsonparser (on go.dev)
Dependency Relation
imports 8 packages, and imported by one package
Package-Level Type Names (only one)
Data types available in valid JSON data.
( ValueType) String() string
ValueType : expvar.Var
ValueType : fmt.Stringer
func Get(data []byte, keys ...string) (value []byte, dataType ValueType, offset int, err error)
const Array
const Boolean
const NotExist
const Null
const Number
const Object
const String
const Unknown
Package-Level Functions (total 32)
ArrayEach is used when iterating arrays, accepts a callback function with the same return arguments as `Get`.
Del - Receives existing data structure, path to delete.
Returns:
`data` - return modified data
func FuzzDelete(data []byte) int func FuzzEachKey(data []byte) int func FuzzGetBoolean(data []byte) int func FuzzGetFloat(data []byte) int func FuzzGetInt(data []byte) int func FuzzGetString(data []byte) int func FuzzGetUnsafeString(data []byte) int func FuzzObjectEach(data []byte) int func FuzzParseBool(data []byte) int func FuzzParseFloat(data []byte) int func FuzzParseInt(data []byte) int func FuzzParseString(data []byte) int func FuzzTokenStart(data []byte) int
Get - Receives data structure, and key path to extract value from.
Returns:
`value` - Pointer to original data structure containing key value, or just empty slice if nothing found or error
`dataType` - Can be: `NotExist`, `String`, `Number`, `Object`, `Array`, `Boolean` or `Null`
`offset` - Offset from provided data structure where key value ends. Used mostly internally, for example for `ArrayEach` helper.
`err` - If key not found or any other parsing issue it should return error. If key not found it also sets `dataType` to `NotExist`
Accept multiple keys to specify path to JSON value (in case of quering nested structures).
If no keys provided it will try to extract closest JSON value (simple ones or object/array), useful for reading streams or arrays, see `ArrayEach` implementation.
GetBoolean returns the value retrieved by `Get`, cast to a bool if possible.
The offset is the same as in `Get`.
If key data type do not match, it will return error.
GetFloat returns the value retrieved by `Get`, cast to a float64 if possible.
The offset is the same as in `Get`.
If key data type do not match, it will return an error.
GetInt returns the value retrieved by `Get`, cast to a int64 if possible.
If key data type do not match, it will return an error.
GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols
If key data type do not match, it will return an error.
GetUnsafeString returns the value retrieved by `Get`, use creates string without memory allocation by mapping string to slice memory. It does not handle escape symbols.
ObjectEach iterates over the key-value pairs of a JSON object, invoking a given callback for each such entry
ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness)
ParseNumber parses a Number ValueType into a Go float64
ParseInt parses a Number ValueType into a Go int64
ParseString parses a String ValueType into a Go string (the main parsing work is unescaping the JSON string)
Set - Receives existing data structure, path to set, and data to set at that key.
Returns:
`value` - modified byte array
`err` - On any parsing error
func StringToBytes(s string) []byte
unescape unescapes the string contained in 'in' and returns it as a slice.
If 'in' contains no escaped characters:
Returns 'in'.
Else, if 'out' is of sufficient capacity (guaranteed if cap(out) >= len(in)):
'out' is used to build the unescaped string and is returned with no extra allocation
Else:
A new slice is allocated and returned.
func WriteToBuffer(buffer []byte, str string) int
Package-Level Variables (total 9)
Errors
Errors
Errors
Errors
Errors
Errors
Errors
Errors
Errors
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |