Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soh335/jsongostruct
generate golang struct from json by go/ast
https://github.com/soh335/jsongostruct
Last synced: 14 days ago
JSON representation
generate golang struct from json by go/ast
- Host: GitHub
- URL: https://github.com/soh335/jsongostruct
- Owner: soh335
- Created: 2013-12-29T09:28:16.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-02-06T02:52:14.000Z (almost 11 years ago)
- Last Synced: 2024-10-11T21:11:51.335Z (about 1 month ago)
- Language: Go
- Homepage: http://soh335.hatenablog.com/entry/2013/12/29/204640
- Size: 176 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jsongostruct
generate golang struct from json by go/ast
## example
```
cat /path/to/jsonfile | jsongostruct
``````json
{
"url": "http://example.com",
"id": 12345,
"name": "web",
"bool": true,
"array": [
"foo",
"bar"
],
"map": {
"foo": "bar",
"dameleon": "dame"
}
}
``````go
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 )