@riku/json-to-ts
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

JSON TO TS

Json to TS

Convert json object to typescript interfaces

Example

Try it Online

Code

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:

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

$ npm install --save json-to-ts

Package Sidebar

Install

npm i @riku/json-to-ts

Weekly Downloads

6,217

Version

2.1.0

License

ISC

Unpacked Size

156 kB

Total Files

53

Last publish

Collaborators

  • riku