modulepackage
0.0.0-20230609154352-e64cfb781a68
Repository: https://github.com/segmentio/jutil.git
Documentation: pkg.go.dev
# README
jutil

Note
Segment has paused maintenance on this project, but may return it to an active status in the future. Issues and pull requests from external contributors are not being considered, although internal contributions may appear from time to time. The project remains available under its open source license for anyone to use.
Go package providing utilities for dealing with JSON content that are missing from the standard library.
# Functions
Escape takes a byte slice as argument and returns the copy of that slice where every special characters have been escaped according to the JSON formatting rules.
EscapeString takes a string as argument and returns the version of that string where every special characters have been escaped according to the JSON formatting rules.
IsEmptyValue returns true if the value given as argument would be considered empty by the standard json package, and therefore not serialized if `omitempty` is set on a struct field with this value.
Length computes the length of the JSON representation of a value of arbitrary type, it's ~10x faster than serializing the content with the standard json package and avoid the extra memory allocations.
LookupStruct behaves like MakeStruct but uses a global cache to avoid having to recreate the struct values when not needed.
MakeStruct takes a Go type as argument and extract information to make a new Struct value.
MakeStructField takes a Go struct field as argument argument and returns its StructType representation.
NewStructCache creates and returns a new StructCache value.
ParseStructField parses the tag of a struct field that may or may not have a `json` tag set, returing the result as a Tag field.
ParseTag parses a raw json tag obtained from a struct field, returining the results as a Tag value.
Quote takes a byte slice as argument and returns the copy of that slice quoted according to the JSON formatting rules.
QuoteString takes a string as argument and returns the version of that string quoted according to the JSON formatting rules.
WriteEscaped outputs a byte slice into an io.Writer where every special character has been escaped according to the JSON formatting rules.
WriteQuoted outputs a byte slice into an io.Writer, quoted according to the JSON formatting rules.
# Structs
StructCache is a simple cache for mapping Go types to Struct values.
StructField represents a single field of a struct and carries information useful to the algorithms of the jutil package.
Tag represents the result of parsing the json tag of a struct field.
# Interfaces
Lengther can be implemented by a value to override the default length deduction algorithm implemented by Length.
# Type aliases
Struct is used to represent a Go structure in internal data structures that cache meta information to make field lookups faster and avoid having to use reflection to lookup the same type information over and over again.