json

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 9 Imported by: 0

README

json

Contains constants and functions for handling JSON data. Substation relies on https://github.com/tidwall/gjson for reading JSON and https://github.com/tidwall/sjson for writing JSON; all features related to reading and writing from those projects are supported, refer to their documentation for further detail.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Types = map[gjson.Type]string{
	0: "Null",
	1: "Boolean",
	2: "Number",
	3: "String",
	4: "Boolean",
	5: "JSON",
}

Types maps gjson.Type to strings.

Functions

func DeepEquals

func DeepEquals(s1, s2 []byte) (bool, error)

DeepEquals performs a deep equals comparison between two byte arrays.

func Delete

func Delete(json []byte, key string) (tmp []byte, err error)

Delete wraps sjson.DeleteBytes.

func Set

func Set(json []byte, key string, value interface{}) (tmp []byte, err error)

Set inserts values into JSON and operates under these conditions (in order):

- If the value is valid JSON (bytes, string, or Result), then it is inserted using SetRaw to properly insert it as nested JSON; this avoids encoding that would otherwise create invalid JSON (e.g. `{\"foo\":\"bar\"}`)

- If the value is bytes, then it is converted to a base64 encoded string (this is the behavior of the standard library's encoding/json package)

- If the value is Result, then it is converted to the underlying GJSON Value

- All other values are inserted as interfaces and are converted by SJSON to the proper format

func SetRaw

func SetRaw(json []byte, key string, value interface{}) (tmp []byte, err error)

SetRaw wraps sjson.SetRawBytes and conditionally converts values to properly insert them as nested JSON.

func Valid

func Valid(data interface{}) bool

Valid conditionally checks if bytes, strings, or Results are valid JSON objects.

Types

type Result

type Result = gjson.Result

Result wraps gjson.Result.

func Get

func Get(json []byte, key string) Result

Get wraps gjson.GetBytes.

Jump to

Keyboard shortcuts

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