https://github.com/watzon/json-to-crystal
Convert JSON structures into Crystal classes with JSON mappings
https://github.com/watzon/json-to-crystal
Last synced: 12 months ago
JSON representation
Convert JSON structures into Crystal classes with JSON mappings
- Host: GitHub
- URL: https://github.com/watzon/json-to-crystal
- Owner: watzon
- Created: 2018-02-17T09:53:18.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-20T01:16:51.000Z (about 8 years ago)
- Last Synced: 2025-04-23T00:46:47.393Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 509 KB
- Stars: 12
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome - watzon/json-to-crystal - Convert JSON structures into Crystal classes with JSON mappings (<a name="JavaScript"></a>JavaScript)
README
# JSON to Crystal
Convert JSON structures to Crystal classes.
A hosted version is available at https://watzon.me/projects/json-to-crystal.
## Usage
```javascript
const JsonToCrystal = require('json-to-crystal')
const json2crystal = new JsonToCrystal()
console.log(json2crystal.parse(`
{
"string": "Hello world",
"boolean": true,
"integer": 12302932,
"float: 232.23,
"another_class": {
"arr": [1, 2, 3],
"hello": "World!"
}
}`))
```
```
class AutoGenerated
JSON.mapping({
string: { type: String },
boolean: { type: Bool },
integer: { type: Int32 },
float: { type: Float64 },
another_class: { type: AnotherClass }
})
class AnotherClass
JSON.mapping({
arr: { type: Array(Int32) },
hello: { type: String }
})
end
end
```