Features:
- No other dependency.
- Adapter to decode Deep nesting json.
- Include Name Cases and tag display options
$ go get github.com/cowkeys/ckjson
-
func NewCkj(name,msg string) *ckjson
new a ckjson client
-
func (*NewCkj)JsonToStruct()
print go struct
package main
import (
"github.com/cowkeys/ckjson"
)
func main() {
json := `{"employees": [
{ "firstName":"Bill" , "salary":10000.00,"flag":true },
{ "first-Name":"George" , "lastName":"Bush","flag":false },
{ "firstName":"Thomas" , "depart_tag":"IT" }]}`
ck := ckjson.NewCkj("TestCK", json)
ck.JsonToStruct()
}
type Employees struct {
FirstName string `json:"firstName"`
Salary float64 `json:"salary"`
Flag bool `json:"flag"`
LastName string `json:"lastName"`
DepartTag string `json:"depart_tag"`
}
type TestCK struct {
Employees Employees `json:"employees"`
}
json := `{"company": {
"name": "google",
"address": {
"country": "us",
"code": 1234,
"loop_one": {
"loop_two": [
1,
2
]
}}}}`
ck3 := ckjson.NewCkj("TestCK", json)
ck3.JsonToStruct()
type LoopTwo struct {
}
type LoopOne struct {
LoopTwo LoopTwo `json:"loop_two"`
}
type Address struct {
Country string `json:"country"`
Code float64 `json:"code"`
LoopOne LoopOne `json:"loop_one"`
}
type Company struct {
Name string `json:"name"`
Address Address `json:"address"`
}
type TestCK struct {
Company Company `json:"company"`
}
//auto filter '_' , '-' , ':' , '.' ...
json := `{ "first_name":"Bill" }`
ck := ckjson.NewCkj("TestCK", t4)
ck.JsonToStruct()//default : aaa_BCD -> AaaBcd (Camel case)
ck.LowerCase = true//aaa_BCD -> Aaabcd (except first char)
ck.JsonToStruct()
ck.UpperCase = true
ck.JsonToStruct()//aaa_BCD -> AAABCD (except first char)
type TestCK struct {
FirstName string
}
type TestCK struct {
Firstname string
}
type TestCK struct {
FIRSTNAME string
}
json := `{ "first_name":"Bill" }`
ck := ckjson.NewCkj("TestCK", json)
ck.JsonToStruct()
ck.JsonTag = false // set not display tag
ck.JsonToStruct()
type TestCK struct {
FirstName string `json:"first_name"`
}
type TestCK struct {
FirstName string
}