package zjson
import "zgo.at/zstd/zjson"
Package zjson provides functions for working with JSON.
Index ¶
- func Get[T Types](j []byte, path string) (T, error)
- func Indent(data []byte, v any, prefix, indent string) ([]byte, error)
- func IndentString(data []byte, v any, prefix, indent string) (string, error)
- func MustGet[T Types](j []byte, path string) T
- func MustIndent(data []byte, v any, prefix, indent string) []byte
- func MustIndentString(data []byte, v any, prefix, indent string) string
- func MustMarshal(v any) []byte
- func MustMarshalIndent(v any, prefix, indent string) []byte
- func MustMarshalIndentString(v any, prefix, indent string) string
- func MustMarshalString(v any) string
- func MustUnmarshal(data []byte, v any)
- func MustUnmarshalTo(data []byte, target reflect.Type) any
- func UnmarshalTo(data []byte, target reflect.Type) (any, error)
- type Int
- type Timestamp
- type Types
Functions ¶
func Get ¶
Get a value from JSON bytes.
Format of path:
foo foo.nested
func Indent ¶
Indent a json string by unmarshalling it and marshalling it with MarshalIndent.
The data will be unmarshalled in to v, which must be a pointer. Example:
Indent(`{"a": "b"}`, &map[string]string{}, "", " ")
func IndentString ¶
IndentString is like Indent, but returns a string.
func MustGet ¶
MustGet is like Get, but will panic on errors.
func MustIndent ¶
MustIndent behaves like Indent but will panic on errors.
func MustIndentString ¶
MustIndentString is like MustIndent, but returns a string.
func MustMarshal ¶
MustMarshal behaves like json.Marshal but will panic on errors.
func MustMarshalIndent ¶
MustMarshalIndent behaves like json.MarshalIndent but will panic on errors.
func MustMarshalIndentString ¶
MustMarshalIndentString is like MustMarshalIndent, but returns a string.
func MustMarshalString ¶
MustMarshalString is like MustMarshal, but returns a string.
func MustUnmarshal ¶
MustUnmarshal behaves like json.Unmarshal but will panic on errors.
func MustUnmarshalTo ¶
MustUnmarshalTo behaves like UnmarshalTo but will panic on errors.
func UnmarshalTo ¶
UnmarshalTo unmarshals the JSON in data to a new instance of target.
Target can be any type that json.Unmarshal can unmarshal to, and doesn't need to be a pointer. The returned value is always a pointer.
Types ¶
type Int ¶
type Int int64
Int for APIs that return numbers as strings.
func (Int) MarshalJSON ¶
Marshal in to JSON.
func (*Int) UnmarshalJSON ¶
Unmarshal a string timestamp as an int.
type Timestamp ¶
Timestamp for APIs that return dates as a numeric Unix timestamp.
func (Timestamp) MarshalJSON ¶
Marshal in to JSON.
func (*Timestamp) UnmarshalJSON ¶
Unmarshal a Unix timestamp as a date.
type Types ¶
Types that can occur in JSON documents.
Source Files ¶
zjson.go
- Version
- v0.0.0-20240930202209-a63c3335042a (latest)
- Published
- Sep 30, 2024
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 2 days ago –
Tools for package owners.