项目
在 GitHub 查看
bashtian/jsonutils
关于
Converter for JSON data to a Go struct or a Java class for GSON
开发工具实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 正在收集历史
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文jsonutils
Converter for JSON data to a Go struct or a Java class for GSON
go get github.com/bashtian/jsonutils/cmd/jsonutil
You can print the structure of a JSON from a URL
jsonutil https://api.github.com/repos/bashtian/jsonutils
or from a file
jsonutil -f file.json
or from stdin
echo '{"some": "data"}' | jsonutil
If you want to print example data as comments, use the -x parameter
jsonutil -x https://api.github.com/repos/bashtian/jsonutils
You can also print Java code
jsonutil -j https://api.github.com/repos/bashtian/jsonutils
Example
JSON
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"balance": 123.45,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021"
},
"phoneNumber": [
{
"type": "home",
"number": "212 555-1234",
"last_call": "2013-01-10T05:27:07Z"
},
{
"type": "fax",
"number": "646 555-4567",
"last_call": "2013-01-10T05:27:07Z"
}
],
"tags": ["music","video"]
}
Go
jsonutil -x -c=false -f Example.json
type Example struct {
Address struct {
City string `json:"city"` // New York
PostalCode string `json:"postalCode"` // 10021
State string `json:"state"` // NY
StreetAddress string `json:"streetAddress"` // 21 2nd Street
} `json:"address"`
Age int64 `json:"age"` // 25
Balance float64 `json:"balance"` // 123.45
FirstName string `json:"firstName"` // John
LastName string `json:"lastName"` // Smith
PhoneNumber []struct {
LastCall string `json:"last_call"` // 2013-01-10T05:27:07Z
Number string `json:"number"` // 212 555-1234
Type string `json:"type"` // home
} `json:"phoneNumber"`
Tags []string `json:"tags"` // music
}
jsonutils -f Example.json
type Example struct {
Address struct {
City string `json:"city"`
PostalCode int64 `json:"postalCode,string"`
State string `json:"state"`
StreetAddress string `json:"streetAddress"`
} `json:"address"`
Age int64 `json:"age"`
Balance float64 `json:"balance"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
PhoneNumber []struct {
LastCall time.Time `json:"last_call"`
Number string `json:"number"`
Type string `json:"type"`
} `json:"phoneNumber"`
Tags []string `json:"tags"`
}
探索相关项目
加载中…