json-to-ts
Version:
Convert json object to typescript interfaces
53 lines (40 loc) • 724 B
Markdown

# Json to TS
### Convert json object to typescript interfaces
# Example
### Code
```javascript
const JsonToTS = require('json-to-ts')
const json = {
cats: [
{name: 'Kittin'},
{name: 'Mittin'}
],
favoriteNumber: 42,
favoriteWord: 'Hello'
}
JsonToTS(json).forEach( typeInterface => {
console.log(typeInterface)
})
```
### Output:
```typescript
interface RootObject {
cats: Cat[];
favoriteNumber: number;
favoriteWord: string;
}
interface Cat {
name: string;
}
```
## Converter
- Array type merging (**Big deal**)
- Union types
- Duplicate type prevention
- Optional types
- Array types
# Setup
```sh
$ npm install --save json-to-ts
```