Skip to content

soh335/jsongostruct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

jsongostruct

generate golang struct from json by go/ast

example

cat /path/to/jsonfile | jsongostruct
{
  "url": "http://example.com",
  "id": 12345,
  "name": "web",
  "bool": true,
  "array": [
    "foo",
    "bar"
  ],
  "map": {
    "foo": "bar",
    "dameleon": "dame"
  }
}
type XXX struct {
        Url   string   `json:"url"`
        Id    float64  `json:"id"`
        Name  string   `json:"name"`
        Bool  bool     `json:"bool"`
        Array []string `json:"array"`
        Map   struct {
                Foo      string `json:"foo"`
                Dameleon string `json:"dameleon"`
        } `json:"map"`
}

TODO

  • testing
  • tag position for struct type
  • nil value handling ( current, null value's type is interface{} )
  • detect array type more smart. ( current, detect type from first element of array )

About

generate golang struct from json by go/ast

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages