https://github.com/cjinhuo/thrift-to-json-schema
Parse Thrift to JSON Schema
https://github.com/cjinhuo/thrift-to-json-schema
json json-schema thrift
Last synced: about 1 month ago
JSON representation
Parse Thrift to JSON Schema
- Host: GitHub
- URL: https://github.com/cjinhuo/thrift-to-json-schema
- Owner: cjinhuo
- Created: 2022-11-04T09:22:42.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-04-17T09:49:52.000Z (about 1 year ago)
- Last Synced: 2025-04-17T23:52:12.473Z (about 1 year ago)
- Topics: json, json-schema, thrift
- Language: TypeScript
- Homepage: https://cjinhuo.github.io/thrift-to-json-schema/
- Size: 1000 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# overview
parse Thrift to JSON schema with typescript
# demo

[Online Demo](https://cjinhuo.github.io/thrift-to-json-schema/)
# install
`pnpm add @trasm/thrift-jsma`
# usage
```js
import { parseThriftToJsonSchema,parseThriftToTypeBox } from '@trasm/thrift-jsma'
const structString = `
# @flag header
struct EmptyStruct {
string field_string
# @schema maxLength:66
double field_double
i32 field_i32
i64 field_i64
bool field_bool
optional string field_optional_string
}
`
const jsonSchema = parseThriftToJsonSchema(structString)
const jsonTypeBox = parseThriftToTypeBox(structString)
```
## syntax
### flag
@flag header: means current struct is root node.
### scheme
@schema xxx: means add additional constraint for field, such as add '@schema maxLength:66' for string type
# references
* parse thrift to AST:https://github.com/creditkarma/thrift-parser
* built JSON schema with typescript:https://github.com/sinclairzx81/typebox