Help us shape the future of Go! Take the 2026 Go Developer Survey

jsutil

package
v1.62.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(w io.Writer, v any) (err error)

Encode marshals the given interface and writes the json bytes to the given writer

func Marshal

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

Marshal converts the given interface into json bytes

func NumberEqual

func NumberEqual(numberExp, numberGot Number) (eq bool)

NumberEqual is comparing the string representation of the json.Number. It fails to compare different formats, 1e10 != 10000000000, although it is the same mathematical value.

func Unmarshal

func Unmarshal(input []byte, output any) (err error)

Unmarshal decodes the input bytes into the output if it is valid cjson

func UnmarshalPlain added in v1.61.0

func UnmarshalPlain(input []byte, output any) (err error)

UnmarshalPlain decodes the input bytes into the output like Unmarshal, but without the cjson comment / trailing comma handling. Use it for JSON which was produced by marshaling or received from a server, that JSON cannot contain comments and running the comment passes over it is wasted work.

It runs on the json/v2 engine: unlike the v1 json.Decoder, which copies the input into its internal buffer and decodes generic values through reflect, jsontext parses the []byte in place (bytes.Buffer fast path) and the `any` tree is built by a plain token loop. Semantics are kept at v1: see unmarshalPlainOpts, and like the old Decoder.Decode, only the first JSON value is read, trailing data is ignored. On error the old v1 decode is re-run on the same input so error values and texts stay byte-identical.

func UnmarshalString

func UnmarshalString(input string, output any) (err error)

UnmarshalString is a wrapper for Unmarshal for string input

Types

type Array

type Array = []any

type Bool

type Bool = bool

type Number

type Number = json.Number

type Object

type Object = map[string]any

type RawMessage

type RawMessage = json.RawMessage

type String

type String = string

Jump to

Keyboard shortcuts

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