json

package
v0.3.0-beta.5.0...-f1c6bd8 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compact

func Compact(src []byte) (string, error)

Compact generates the JSON-encoded src with insignificant space characters elided.

func HTMLEscape

func HTMLEscape(src []byte) string

HTMLEscape returns the JSON-encoded src with <, >, &, U+2028 and U+2029 characters inside string literals changed to \u003c, \u003e, \u0026, \u2028, \u2029 so that the JSON will be safe to embed inside HTML <script> tags. For historical reasons, web browsers don't honor standard HTML escaping within <script> tags, so an alternative JSON encoding must be used.

func Indent

func Indent(src []byte, prefix, indent string) (string, error)

Indent creates an indented form of the JSON-encoded src. Each element in a JSON object or array begins on a new, indented line beginning with prefix followed by one or more copies of indent according to the indentation nesting. The data appended to dst does not begin with the prefix nor any indentation, to make it easier to embed inside other formatted JSON data. Although leading space characters (space, tab, carriage return, newline) at the beginning of src are dropped, trailing space characters at the end of src are preserved and copied to dst. For example, if src has no trailing spaces, neither will dst; if src ends in a trailing newline, so will dst.

func Marshal

func Marshal(v cue.Value) (string, error)

Marshal returns the JSON encoding of v.

func MarshalStream

func MarshalStream(v cue.Value) (string, error)

MarshalStream turns a list into a stream of JSON objects.

func Unmarshal

func Unmarshal(b []byte) (ast.Expr, error)

Unmarshal parses the JSON-encoded data.

func Valid

func Valid(data []byte) bool

Valid reports whether data is a valid JSON encoding.

func Validate

func Validate(b []byte, v cue.Value) (bool, error)

Validate validates JSON and confirms it matches the constraints specified by v.

Types

This section is empty.

Jump to

Keyboard shortcuts

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