# json-to-ts

> Convert json object to typescript interfaces

Latest version **2.1.0** (published 2024-04-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install json-to-ts
pnpm add json-to-ts
yarn add json-to-ts
bun add json-to-ts
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2024-04-18 |
| First published | 2017-04-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 153.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | https://github.com/mariusalch |
| Maintainers | mariusalchimavicius |
| Keywords | typescript, ts, convert, json, util, lib, types |

## Links

- npm: https://www.npmjs.com/package/json-to-ts
- Repository: https://github.com/MariusAlch/json-to-ts
- Homepage: https://github.com/MariusAlch/json-to-ts#readme
- Issues: https://github.com/MariusAlch/json-to-ts/issues
- npm.io page: https://npm.io/package/json-to-ts

## Dependencies (3)

- [hash.js](https://npm.io/package/hash.js.md) ^1.0.3
- [es7-shim](https://npm.io/package/es7-shim.md) ^6.0.0
- [pluralize](https://npm.io/package/pluralize.md) ^3.1.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.1.0 (latest) — 2024-04-18
- 1.7.0 — 2020-03-11
- 1.6.0 — 2019-06-24
- 1.5.4 — 2017-11-21
- 1.5.3 — 2017-08-04
- 1.5.2 — 2017-07-27
- 1.5.1 — 2017-07-27
- 1.5.0 — 2017-07-26
- 1.4.4 — 2017-07-26
- 1.4.3 — 2017-06-14
- 1.4.2 — 2017-06-10
- 1.4.1 — 2017-06-10
- 1.4.0 — 2017-06-10
- 1.3.1 — 2017-06-10
- 1.3.0 — 2017-06-10
- … 10 more at https://npm.io/package/json-to-ts/versions

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

---
_Source: https://npm.io/package/json-to-ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
