Based on original code in javascript from "JSON-to-Go" from Matt Holt
Translates JSON into a Go type definition.
Things to note:
- This code sometimes has to make some assumptions, so give the output a once-over.
- In an array of objects, it is assumed that the first object is representative of the rest of them.
Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.
# go build -o json-to-go main.go
-
Read JSON file:
json-to-go sample.json
-
Read JSON file from stdin:
json-to-go < sample.json cat sample.json | json-to-go
Original javascript JSON-to-Go is brought to you by Matt Holt (mholt6).