jsonutils

package module
v0.0.0-...-1b223d6 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package jsonutils provides helpers to work with JSON.

These utilities work with dynamic go structures to and from JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConcatJSON

func ConcatJSON(blobs ...[]byte) []byte

ConcatJSON concatenates multiple json objects efficiently

func FromDynamicJSON

func FromDynamicJSON(source, target interface{}) error

FromDynamicJSON turns a go value into a properly JSON typed structure.

"Dynamic JSON" refers to what you get when unmarshaling JSON into an untyped interface{}, i.e. objects are represented by map[string]interface{}, arrays by []interface{}, and all numbers are represented as float64.

func ReadJSON

func ReadJSON(data []byte, value interface{}) error

ReadJSON unmarshals JSON data into a data structure.

The difference with json.Unmarshal is that it may check among several alternatives to do so.

Currently this allows types that are [easyjson.Unmarshaler]s to use that route to process JSON.

func WriteJSON

func WriteJSON(value interface{}) ([]byte, error)

WriteJSON marshals a data structure as JSON.

The difference with json.Marshal is that it may check among several alternatives to do so.

Currently this allows types that are [easyjson.Marshaler]s to use that route to produce JSON.

Types

type JSONMapItem

type JSONMapItem struct {
	Key   string
	Value any
}

JSONMapItem represents the value of a key in a JSON object held by JSONMapSlice.

Notice that JSONMapItem should not be marshaled to or unmarshaled from JSON directly, use this type as part of a JSONMapSlice when dealing with JSON bytes.

func (JSONMapItem) MarshalEasyJSON

func (s JSONMapItem) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON renders a JSONMapItem as JSON bytes, using easyJSON

func (*JSONMapItem) UnmarshalEasyJSON

func (s *JSONMapItem) UnmarshalEasyJSON(in *jlexer.Lexer)

UnmarshalEasyJSON builds a JSONMapItem from JSON bytes, using easyJSON

type JSONMapSlice

type JSONMapSlice []JSONMapItem

JSONMapSlice represents a JSON object, with the order of keys maintained.

func (JSONMapSlice) MarshalEasyJSON

func (s JSONMapSlice) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON renders a JSONMapSlice as JSON bytes, using easyJSON

func (JSONMapSlice) MarshalJSON

func (s JSONMapSlice) MarshalJSON() ([]byte, error)

MarshalJSON renders a JSONMapSlice as JSON bytes, preserving the order of keys.

func (*JSONMapSlice) UnmarshalEasyJSON

func (s *JSONMapSlice) UnmarshalEasyJSON(in *jlexer.Lexer)

UnmarshalEasyJSON builds a JSONMapSlice from JSON bytes, using easyJSON

func (*JSONMapSlice) UnmarshalJSON

func (s *JSONMapSlice) UnmarshalJSON(data []byte) error

UnmarshalJSON builds a JSONMapSlice from JSON bytes, preserving the order of keys.

Inner objects are unmarshaled as JSONMapSlice slices and not map[string]any.

Jump to

Keyboard shortcuts

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