Categorycode.cloudfoundry.org/jsonry
modulepackage
1.1.4
Repository: https://github.com/cloudfoundry/jsonry.git
Documentation: pkg.go.dev

# README

test go.dev reference

JSONry

A Go library and notation for converting between a Go struct and JSON.

import "code.cloudfoundry.org/jsonry"

s := struct {
  GUID string `jsonry:"relationships.space.data.guid"`
}{
  GUID: "267758c0-985b-11ea-b9ac-48bf6bec2d78",
}

json, _ := jsonry.Marshal(s)
fmt.Println(string(json))

Will generate the following JSON:

{
  "relationships": {
    "space": {
      "data": {
        "guid": "267758c0-985b-11ea-b9ac-48bf6bec2d78"
      }
    }
  }
}

The operation is reversible using Unmarshal(). The key advantage is that nested JSON can be generated and parsed without the need to create intermediate Go structures. Check out the documentation for details.

JSONry started life in the Cloud Foundry CLI project. It has been extracted so that it can be used in other projects too.

More information:

# Functions

Marshal converts the specified Go struct into JSON.
Unmarshal parses the specified JSON into the specified Go struct receiver.

# Interfaces

Omissible is the interface implemented by types that indicate whether they should be omitted when being marshaled.