Documentation ¶
Overview ¶
Package js provides some simple json utilities: MapSlice, for preserving map key order when unmarshaling, and Builder for writing json-like data without marshaling.
Index ¶
- Constants
- Variables
- func Embrace(style [2]rune, cb func(*Builder)) string
- type Builder
- func (out *Builder) B(b bool) *Builder
- func (out *Builder) Brace(style [2]rune, cb func(*Builder)) *Builder
- func (out *Builder) F(f float64) *Builder
- func (out *Builder) If(b bool, cb func(*Builder)) *Builder
- func (out *Builder) Kv(k, v string) *Builder
- func (out *Builder) N(n int) *Builder
- func (out *Builder) Q(el string) *Builder
- func (out *Builder) R(els ...rune) *Builder
- func (out *Builder) Raw(el string) *Builder
- func (out *Builder) Str(s string) *Builder
- type MapItem
- type MapSlice
Constants ¶
View Source
const Colon = ':'
View Source
const Comma = ','
View Source
const False = "false"
View Source
const Null = "null"
View Source
const Percent = '%'
View Source
const Quote = '"'
View Source
const Score = '_'
View Source
const Space = ' '
View Source
const True = "true"
Variables ¶
View Source
var Array = [2]rune{'[', ']'}
View Source
var Obj = [2]rune{'{', '}'}
View Source
var Quotes = [2]rune{Quote, Quote}
Functions ¶
Types ¶
type Builder ¶
wraps strings builder with some json helper functions. Useful for cases where writing json directly is easier than first composing go data structures and then marshaling via package json/encoding.
type MapItem ¶
type MapItem struct { Key string Msg json.RawMessage }
type MapSlice ¶
type MapSlice []MapItem
used when reading json to preserve the specified order of keys "no way to preserve the order of map keys" https://github.com/golang/go/issues/27179
func (*MapSlice) UnmarshalJSON ¶
expects we're unmarshaling a valid json object.
Click to show internal directories.
Click to hide internal directories.