https://github.com/hacxy/json2typebox
Creating TypeBox code from Json Data
https://github.com/hacxy/json2typebox
json2typebox typebox typescript
Last synced: 10 months ago
JSON representation
Creating TypeBox code from Json Data
- Host: GitHub
- URL: https://github.com/hacxy/json2typebox
- Owner: hacxy
- License: mit
- Created: 2024-10-26T02:45:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-31T12:00:48.000Z (over 1 year ago)
- Last Synced: 2024-12-03T01:37:20.135Z (over 1 year ago)
- Topics: json2typebox, typebox, typescript
- Language: TypeScript
- Homepage:
- Size: 224 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Json2Typebox
If you need cli tools. see [json2typebox-cli](https://github.com/hacxy/json2typebox-cli).
## Overview
Json2Typebox is a code generation tool that transforms Json Data into [TypeBox](https://github.com/sinclairzx81/typebox) type.
Browsers and Node.js can both be used.
## Install
```bash
npm install json2typebox --save
```
### Example
```ts
import json2typebox from 'json2typebox';
await json2typebox('{"id": 1, "name": "hacxy"}', 'Root');
/*
import { Type, Static } from '@sinclair/typebox'
export type Data = Static
export const Data = Type.Object({
id: Type.Number(),
name: Type.String()
})
*/
```
function: `json2typebox()`
> **json2typebox**(`json`, `name`): `Promise`\<`string`\>
### Params
| name | types | default | description |
| :----- | :------- | :---------- | :--------------- |
| `json` | `string` | `undefined` | json data |
| `name` | `string` | `'Root'` | define type name |
### Returns
`Promise`\<`string`\>
## Related
- json2typebox-cli: [https://github.com/hacxy/json2typebox-cli](https://github.com/hacxy/json2typebox-cli)
- json2ts: [https://github.com/hacxy/json2ts](https://github.com/hacxy/json2ts)
## License
[MIT](./LICENSE) License © 2023-PRESENT [Hacxy](https://github.com/hacxy)