json

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package json provide functions for marshalling an unmarshalling types to JSON. These functions are meant to be utilized inside of structs that implement json.Unmarshaler and json.Marshaler interfaces. This package provides the additional functionality of writing fields that are not in the struct when marshalling to a field called AdditionalFields if that field exists and is a map[string]interface{}. When marshalling, if the struct has all the same prerequisites, it will uses the keys in AdditionalFields as extra fields. This package uses encoding/json underneath.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(i interface{}) ([]byte, error)

Marshal is used to marshal a type into its JSON representation. It wraps the stdlib calls in order to marshal a struct or *struct so that a field called "AdditionalFields" of type map[string]interface{} with "-" used inside struct tag `json:"-"` can be marshalled as if they were fields within the struct.

func MarshalRaw

func MarshalRaw(i interface{}) json.RawMessage

MarshalRaw marshals i into a json.RawMessage. If I cannot be marshalled, this will panic. This is exposed to help test AdditionalField values which are stored as json.RawMessage.

func Unmarshal

func Unmarshal(b []byte, i interface{}) error

Unmarshal unmarshals a []byte representing JSON into i, which must be a *struct. In addition, if the struct has a field called AdditionalFields of type map[string]interface{}, JSON data representing fields not in the struct will be written as key/value pairs to AdditionalFields.

Types

This section is empty.

Directories

Path Synopsis
types
time
Package time provides for custom types to translate time from JSON and other formats into time.Time objects.
Package time provides for custom types to translate time from JSON and other formats into time.Time objects.

Jump to

Keyboard shortcuts

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