marshal

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeDocument

func NormalizeDocument(document []byte, normalizers ...Normalizer) ([]byte, error)

NormalizeDocument accepts a JSON document and applies (in order) the given normalizers to it.

Types

type Normalizer

type Normalizer func(map[string]interface{})

func KeyAlias

func KeyAlias(alias string, aliasFor string) Normalizer

KeyAlias returns a Normalizer that converts an aliased key to its original form. E.g. when working with LinkedData in JSON form, `@context` is an alias for `context`. This Normalizer would convert the `@context` key to `context`.

func Plural

func Plural(key string) Normalizer

Plural returns a Normalizer that converts a singular values (string/numeric/bool/object) to an array. This makes unmarshalling DID Documents or Verifiable Credentials easier, since those formats allow certain properties to be either a singular value or an array of values.

Example input: {"message": "Hello, World"} Example output (if 'message' is supplied in 'pluralKeys'): {"message": ["Hello, World"]}

This function does not support nested keys.

func Unplural

func Unplural(key string) Normalizer

Unplural returns a Normalizer that converts arrays with a single value into a singular value. It is the opposite of the Plural normalizer.

Jump to

Keyboard shortcuts

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