Create a go struct out of a json file. This will take either pipe from stdin or from a json file. (Todo: Perhaps copy it from clipboard???)
This is actually a rewrite of the json2struct command found in github.com/yudppp/json2struct I changed it to suit my needs. I've useed structs generated by this in many programs, some of them are in production without an issue. That being said, it's free, it's MIT licensed. If it blows up and causes major damage in any way -- well I didn't force you to use it.
::Note:: if no -o is given, output goes to stdout.
json2struct -f infile.json -o outfile.go -n structname
This will output in a file. outfile.go.
json2struct -f infile.json -n structname
cat somejsonfile.json | json2struct -n structname
If you're not piping input or if -f is not used. The program will pull whats on the clipboard and use that.
- Copy json to your clipboard
json2struct -o outfile.go
Example:
$ json2struct -o outfile.json
$ cat outfile.json
{
type Data struct {
Configurations []DataConfiguration `json:"configurations"`
Version string `json:"version"`
}
type DataConfiguration struct {
Args []interface{} `json:"args"`
Env DataConfigurationEnv `json:"env"`
Mode string `json:"mode"`
Name string `json:"name"`
Program string `json:"program"`
Request string `json:"request"`
Type string `json:"type"`
}
type DataConfigurationEnv struct {
}