Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

json-to-ts

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-to-ts

Convert json object to typescript interfaces

latest
Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
66K
-14.18%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

typescript

FAQs

Package last updated on 18 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts