json2struct

command module
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 7 Imported by: 0

README

json2struct

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.

Usage:

File In / file out

json2struct -f infile.json -o outfile.go -n structname

This will output in a file. outfile.go.

Pipe in / file out

json2struct -f infile.json -n structname

Pipe in / standard out

cat somejsonfile.json | json2struct  -n structname

Get JSON from clipboard:

If you're not piping input or if -f is not used. The program will pull whats on the clipboard and use that.

  1. 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 {
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL