An open API service indexing awesome lists of open source software.

https://github.com/MariusAlch/json-to-ts

Convert jsons to typescript interfaces
https://github.com/MariusAlch/json-to-ts

Last synced: about 4 hours ago
JSON representation

Convert jsons to typescript interfaces

Awesome Lists containing this project

README

        

![JSON TO TS](https://image.ibb.co/fTb60k/icon.png)

# 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
```