Home

Awesome

Json2Typebox

If you need cli tools. see json2typebox-cli.

Overview

Json2Typebox is a code generation tool that transforms Json Data into TypeBox type.

Browsers and Node.js can both be used.

Install

npm install json2typebox --save

Example

import json2typebox from 'json2typebox';

json2typebox(`{"id": 1, "name": "hacxy"}`, 'Root').then((code) => {
  console.log(code);
  /*
    import { Type, Static } from '@sinclair/typebox'

    export type Data = Static<typeof Data>
    export const Data = Type.Object({
      id: Type.Number(),
      name: Type.String()
    })
 */
});

function: json2typebox()

json2typebox(json, name): Promise<string>

Params

nametypesdefaultdescription
jsonstringundefinedjson data
namestring'Root'define type name

Returns

Promise<string>

Related

License

MIT