package json

import "github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/json"

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

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.

Source Files

json.go mapslice.go marshal.go struct.go

Directories

PathSynopsis
apps/internal/json/types
apps/internal/json/types/timePackage time provides for custom types to translate time from JSON and other formats into time.Time objects.
Version
v1.4.2 (latest)
Published
Mar 26, 2025
Platform
linux/amd64
Imports
6 packages
Last checked
2 days ago

Tools for package owners.