jason

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 1 Imported by: 2

README

Dynamic JSON in Go

Go Reference Go Report

Documentation

Overview

Package jason helps deal with dynamic JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsA added in v0.4.0

func AsA[T any](j RawValue) (v T, err error)

AsA unmarshals j into a value of type T.

Example of converting j into a time instant:

if v, err := jason.AsA[time.Time](j); err == nil { ... }

func IsA added in v0.4.0

func IsA[T any](j RawValue) bool

IsA checks whether j can be unmarshaled into type T.

Example of testing whether j can be converted into a time instant:

if jason.IsA[time.Time](j) { ... }

func ToA added in v0.4.0

func ToA[T any](j RawValue) (v T)

ToA unmarshals j into a value of type T, panics on error.

Example of converting j into a time instant:

jason.ToA[time.Time](j)

Types

type Array

type Array = []any

Array is a JSON array: an ordered collection of values.

Example of an Array literal:

jason.Array{1, 2, 3}

type Number

type Number = json.Number

Number is an encoded JSON number.

It has arbitrary precision, and can be easily converted to a float64 or int64.

Example of a Number literal:

jason.Number("10")

type Object

type Object = map[string]any

Object is a JSON object: an unordered set of name/value pairs.

Example of an Object literal:

jason.Object{"abc": true}

type RawArray added in v0.2.0

type RawArray = []RawValue

RawArray is an array of RawValue's.

type RawObject added in v0.2.0

type RawObject = map[string]RawValue

RawObject is an object of RawValue's.

type RawValue added in v0.3.0

type RawValue = json.RawMessage

RawValue is a raw encoded JSON value.

It implements json.Marshaler and json.Unmarshaler, and can be used to delay/precompute JSON decoding/encoding.

Example of a RawValue literal:

jason.RawValue("false")

func From

func From(v any) RawValue

From marshals v into a RawValue, panics on error.

Example of creating a RawValue from a time instant:

jason.From(time.Now())

Jump to

Keyboard shortcuts

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