hjson

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte, v any) (err error)

func Encode

func Encode(v any, pretty ...bool) (r json.RawValue)

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal returns the Hjson encoding of v using default options.

See MarshalWithOptions.

func MarshalWithOptions

func MarshalWithOptions(v interface{}, options EncoderOptions) ([]byte, error)

MarshalWithOptions returns the Hjson encoding of v.

Marshal traverses the value v recursively.

Boolean values encode as JSON booleans.

Floating point, integer, and Number values encode as JSON numbers.

String values encode as Hjson strings (quoteless, multiline or JSON).

Array and slice values encode as JSON arrays.

Map values encode as JSON objects. The map's key type must be a string. The map keys are sorted and used as JSON object keys.

Pointer values encode as the value pointed to. A nil pointer encodes as the null JSON value.

Interface values encode as the value contained in the interface. A nil interface value encodes as the null JSON value.

JSON cannot represent cyclic data structures and Marshal does not handle them. Passing cyclic structures to Marshal will result in an infinite recursion.

func Unmarshal

func Unmarshal(data []byte, v interface{}) (err error)

Unmarshal parses the Hjson-encoded data and stores the result in the value pointed to by v.

Unmarshal uses the inverse of the encodings that Marshal uses, allocating maps, slices, and pointers as necessary.

Types

type EncoderOptions

type EncoderOptions struct {
	// End of line, should be either \n or \r\n
	Eol string
	// Place braces on the same line
	BracesSameLine bool
	// Deprecated: Hjson always emits braces
	EmitRootBraces bool
	// Always place string in quotes
	QuoteAlways bool
	// Indent string
	IndentBy string
	// Allow the -0 value (unlike ES6)
	AllowMinusZero bool
	// Encode unknown values as 'null'
	UnknownAsNull bool
}

EncoderOptions defines options for encoding to Hjson.

func DefaultOptions

func DefaultOptions() EncoderOptions

DefaultOptions returns the default encoding options.

Jump to

Keyboard shortcuts

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