1.0.1 • Published 2 years ago
@jodd/json-to-typescript v1.0.1
JSON to Typescript Types Generator
Install Dependency
npm install @jodd/json-to-typescript
Official NPM Package Link
Apply white-space
property as pre-wrap
to show magically ⚡ formatted text on the browser
// JSX Example
import React from 'react';
import { generateTypes } from '@jodd/json-to-typescript';
export default function App() {
const json = `{
"title": "Apple",
"quantity": 300,
"isSoldOut": false,
"purchaser": null
}
`;
const { result } = generateTypes(json, 'Fruit');
return (
<div>
<p style={{ whiteSpace: 'pre-wrap' }}>{result}</p>
</div>
);
}
Result
export type Fruit = {
title: string;
quantity: number;
isSoldOut: boolean;
purchaser: null;
};