gojson generates go struct definitions from json or yaml documents.
$ curl -s https://api.github.com/users/jniltinho|gojson -name=Users
package main
type Users struct {
AvatarURL string `json:"avatar_url"`
Bio string `json:"bio"`
Blog string `json:"blog"`
Company string `json:"company"`
CreatedAt string `json:"created_at"`
Email interface{} `json:"email"`
EventsURL string `json:"events_url"`
Followers int64 `json:"followers"`
FollowersURL string `json:"followers_url"`
Following int64 `json:"following"`
FollowingURL string `json:"following_url"`
GistsURL string `json:"gists_url"`
GravatarID string `json:"gravatar_id"`
Hireable interface{} `json:"hireable"`
HTMLURL string `json:"html_url"`
ID int64 `json:"id"`
Location string `json:"location"`
Login string `json:"login"`
Name string `json:"name"`
NodeID string `json:"node_id"`
OrganizationsURL string `json:"organizations_url"`
PublicGists int64 `json:"public_gists"`
PublicRepos int64 `json:"public_repos"`
ReceivedEventsURL string `json:"received_events_url"`
ReposURL string `json:"repos_url"`
SiteAdmin bool `json:"site_admin"`
StarredURL string `json:"starred_url"`
SubscriptionsURL string `json:"subscriptions_url"`
TwitterUsername interface{} `json:"twitter_username"`
Type string `json:"type"`
UpdatedAt string `json:"updated_at"`
URL string `json:"url"`
}
go install -ldflags="-s -w" github.com/jniltinho/gojson/gojson@latest
Assuming $GOPATH/bin
is in your PATH
, you can now invoke gojson
directly.
go get github.com/jniltinho/gojson/gojson
$ git clone https://github.com/jniltinho/gojson.git
$ cd gojson
$ go test
Building CLI
$ go build -o _build/gojson ./gojson
Installing CLI
$ go install ./gojson
Formatting
$ gofmt -w -e -s -l .
github.com/str1ngs/jflect
gojson is free software distributed under Version 3 of the GNU Public License.
As of the time of writing, this is the same license used for gcc (and therefore gccgo), so it is unlikely to restrict use in any way. Note that the GPL does not extend to any output generated by gojson; the GPL only applies to software which includes copies of gojson itself.