JSON-TSC
A plugin that makes it easier to convert JSON to Typescript types.
![NPM version](https://img.shields.io/npm/v/json-tsc?color=c95f8b&label=)
🤹♂️ Preview
Features
- 🌈 Simple - Provides the easiest API to convert JSON into Typescript interaface.
- 🎉 Ts Supported - Support TypeScript & type checked & type inference.
Usage
npm i json-tsc -D
Import JSON_TSC
into the file you want to convert.
import { JSON_TSC } from "json-tsc";
const JSON_TEST = {
"a": 0,
"b": {
"c": "string",
"d": [1, 2, 3],
"e": {
"f": true,
"g": null,
},
},
};
const json_tsc = new JSON_TSC({
prependWithO: true,
sortAlphabetically: false,
prependExport: true,
useArrayGeneric: false,
optionalFields: false,
prefix: "",
});
const result = json_tsc.transform(JSON_TEST);
type JSON_TSC = ORootObject;
export interface ORootObject {
a: number;
b: OB;
}
export interface OB {
c: string;
d: number[];
e: OE;
}
export interface OE {
f: boolean;
g: any;
}
Config
export interface JSON_TSC_CONFIG {
prependWithO: boolean
sortAlphabetically: boolean
prependExport: boolean
useArrayGeneric: boolean
optionalFields: boolean
prefix: string
rootObjectName: string
}
![image](https://raw.githubusercontent.com/imageList/imglist/master/20221027234023.png)
Development
You can see the preview of the following commands:
npm run build
Then you can run playground to see the result.
npm run play
If you want start the dev server, you can run:
npm run dev
License
MIT License © 2022 yzh990918