serialization

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Serialization utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlattenStructToJSON

func FlattenStructToJSON(value any) (map[string]any, error)

Flatten a struct to a JSON object.

We have many structs that look like

type Foo struct {
   Field1 A
   Field2 B
   SomeMap map[string]Foobar
}

That are meant to be converted to JSON as

{
   "field1": ...,
   "field2": ...,
   "key1": ..., // Key of SomeMap
   "key2": ..., // Key of SomeMap
   ...
}

This function handles conversion to a JSON object that can then be serialized using the regular `json.Marshal`.

Conventions:

  • all field names MUST have a tag `json`.
  • a field holding a map MAY have a tag `flatten`, in which case the map is flattened into the containing struct, as above
  • a field hodling a struct MAY have a tag `flatten`, in which case the struct is flattened into the containing struct
  • a field MAY specify `omitempty` as the second value of `json` to specify that zero values should be skipped

This function should never panic.

Types

This section is empty.

Jump to

Keyboard shortcuts

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