Skip to content

Latest commit

 

History

History
41 lines (34 loc) · 1.34 KB

README.md

File metadata and controls

41 lines (34 loc) · 1.34 KB

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: