jsonext

package
v0.0.0-...-653826b Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

This GO-lang JSON Parser will support extensions - meaning unknown properties in the JSON. If you include a property in your struct with the exts json tag then all unknown JSON properties will be placed in there. For example, struct that looks like:

struct {
  Name string `json:"name"`
  Extras map[string]interface{} `json:",exts"`
}

Will result in this JSON:

{ "name": "john",
  "address": "123 main street" }

being parsed as:

struct {
  Name: "john",
  Extras: {
    "address": "123 main street",
  }
}

To access a property that might be defined in your struct or within an extension (meaning, be forwards and backward compatible), use:

	StructGet(structValue, key)

For example:

	address, err := jsonext.StructGet( person, "address" )

will find address whether it ends up being defined as a sibling to Name or ends up being parsed into Extras.

See: future/future.go for a full example of how to use it.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

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

Note will not work for cases where the ext is in a struct that is in a

non-struct top level thing - e.g. a struct in a map

func MarshalIndent

func MarshalIndent(obj interface{}, prefix, indent string) ([]byte, error)

func StructGet

func StructGet(obj interface{}, key string) (interface{}, error)

StructGet will return the value of the field in the struct whose name is 'key'. If there is no field by that name then it'll look in the "extension" map if one exists. If `obj` isn't a struct, or `key` can not be found then this will return `nil` and `error` will be non-nil.

func Unmarshal

func Unmarshal(jsonStr []byte, obj interface{}) error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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