# json-types-generator

> a json types generator

Latest version **0.0.5** (published 2021-08-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-types-generator
pnpm add json-types-generator
yarn add json-types-generator
bun add json-types-generator
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2021-08-29 |
| First published | 2021-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 39 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | xdoer |
| Maintainers | thomas_han |
| Keywords | json, typescript, types |

## Links

- npm: https://www.npmjs.com/package/json-types-generator
- Repository: https://github.com/xdoer/json-types-generator
- Homepage: https://github.com/xdoer/json-types-generator#readme
- Issues: https://github.com/xdoer/json-types-generator/issues
- npm.io page: https://npm.io/package/json-types-generator

## Dependencies (1)

- [ts-morph](https://npm.io/package/ts-morph.md) ^11.0.3

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

- 0.0.5 (latest) — 2021-08-29
- 0.0.4 — 2021-08-29
- 0.0.3 — 2021-08-27
- 0.0.2 — 2021-08-26
- 0.0.1 — 2021-08-25

## README

# JSON Types Generator

A Json Types Generator For TypeScript

## Install

```bash
yarn add json-types-generator
```

## Usage

```ts
import jsonTypesGenerator from 'json-types-generator'

const jsonStr = `
{
  "date": "2021-08-28",
  "season": "ordinary",
  "season_week": 21,
  "celebrations": [
    {
      "title": "Saint Augustine of Hippo, bishop and doctor of the Church",
      "colour": "white",
      "rank": "memorial",
      "rank_num": 3.1
    }
  ],
  "weekday": "saturday"
}
`

jsonTypesGenerator({
  data: jsonStr,
  outPutPath: '/User/xdoer/types.ts',
  rootInterfaceName: 'ChinaRegion',
  customInterfaceName(key, value, data) {
    if (key === 'aa') return 'Province'
  },
})
```

## Options

| Options             | Type                                                   | Require | Meaning                             |
| ------------------- | ------------------------------------------------------ | ------- | ----------------------------------- |
| data                | string \| json object                                  | -[x]    | Json string or object               |
| outPutPath          | string                                                 | -[x]    | types file output path              |
| rootInterfaceName   | string                                                 | -[x]    | root interface name you want to get |
| overwrite           | boolean, default is true                               | -[ ]    | rewrite file when file is exist     |
| customInterfaceName | (key: string, value: any, data: any) => string \| void | -[ ]    | custom intermediate interface       |

## Test

You can add json file to `test/data` folder, and run `npm test` command, then observe whether the output of `test/output` meets expectations

## Other

How to use this in Restful-API ? See [here](https://github.com/xdoer/PreQuest/tree/main/packages/response-types-generator)

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