-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Readme should reference documentation
- Loading branch information
Showing
1 changed file
with
30 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,33 @@ | ||
[![CI](https://github.com/cloudfoundry/jsonry/workflows/Go/badge.svg)](https://github.com/cloudfoundry/jsonry/actions?query=workflow%3AGo) | ||
[![GoDoc](https://godoc.org/code.cloudfoundry.org/jsonry?status.png)](https://godoc.org/code.cloudfoundry.org/jsonry) | ||
# JSONry | ||
|
||
A Go module for converting between a Go `struct` and JSON. | ||
A Go library and notation for converting between a Go `struct` and JSON. | ||
|
||
JSONry is being extracted from the [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) project. It exists to make it easier | ||
to define the translation between complex JSON data and Go structures. | ||
```go | ||
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: | ||
```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](https://godoc.org/code.cloudfoundry.org/jsonry) for details. | ||
|
||
JSONry started life in the [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) project. It has been extracted so | ||
that it can be used in other projects too. |