comparing with , it identifys int/int64/float model more precise. Apart from this, json2struct generates
single type name for embedding struct model if there are 2 or more json input.
json data
{
"aid": 6858121093648023822,
"bid": 6858073458614731015,
"show_more": true,
"coupon": {
"6858121093648023822": {
"max_coupon": {
"credit": 8
},
"total_stock": 2
}
}
}
`quicktype` result
type Welcome struct {
AID *float64 `json:"aid,omitempty"`
BID *float64 `json:"bid,omitempty"`
ShowMore *bool `json:"show_more,omitempty"`
MaxCouponDefault map[string] Coupon `json:"coupon,omitempty"`
}
type Coupon struct {
MaxCoupon *MaxCoupon `json:"max_coupon,omitempty"`
TotalStock *int64 `json:"total_stock,omitempty"`
}
type MaxCoupon struct {
Credit *int64 `json:"credit,omitempty"`
}
we expect
type Welcome struct {
ShareComboID *int64 `json:"share_combo_id,omitempty"`
AddressComboID *int64 `json:"address_combo_id,omitempty"`
ShowMoreTalentAreas *bool `json:"show_more_talent_areas,omitempty"`
ShowMoreBrandAreas *bool `json:"show_more_brand_areas,omitempty"`
MaxCouponDefault map[int64]MaxCouponDefault `json:"max_coupon_default,omitempty"`
}
for more, if we translate the following json to the same go file, the model `Coupon、MaxCoupon` will be double definition.
{
"coupon": {
"6858121093648023822": {
"max_coupon": {
"credit": 818
},
"total_stock": 2000
}
}
make it protobuf defination
Installation
go get github.com/buptbill220/json2struct/json2struct