• Stars
    star
    398
  • Rank 108,325 (Top 3 %)
  • Language
    TypeScript
  • Created over 7 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Convert jsons to typescript interfaces

JSON TO TS

Json to TS

Convert json object to typescript interfaces

Example

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