https://github.com/codeindex2937/oojson
Generate code from JSON
https://github.com/codeindex2937/oojson
codegen json
Last synced: 4 months ago
JSON representation
Generate code from JSON
- Host: GitHub
- URL: https://github.com/codeindex2937/oojson
- Owner: codeindex2937
- Created: 2023-10-09T09:26:56.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-10-04T06:07:31.000Z (9 months ago)
- Last Synced: 2025-10-04T08:22:42.230Z (9 months ago)
- Topics: codegen, json
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# oojson
Generate data object code from JSON
## Example
```go
d := json.NewDecoder(bytes.NewBufferString(`{
"name": "Tom",
"age": 50,
"height": 175.0,
"trace": [[0.0, 0.0], [0.1, 0.2]],
"properties": [{"type": "pet", "value": "cat"}]
}`))
d.UseNumber()
var obj interface{}
if err := d.Decode(&obj); err != nil {
log.Fatal(err)
}
value := &oojson.Value{}
value.Observe(obj)
rawCode, _ := oojson.GetGoType(value, 0, oojson.DefaultGoOption())
goCode, err := format.Source([]byte(rawCode))
if err != nil {
log.Fatal(err)
}
fmt.Printf("go:\n%v\n", string(goCode))
_, javaCode := oojson.GetJavaType(value, "Test", " ", oojson.DefaultJavaOption())
fmt.Printf("java:\n%v\n", string(javaCode))
```
## Reference
[go-jsonstruct](https://github.com/twpayne/go-jsonstruct)