Schema Studio · @trasm/thrift-jsma
Thrift to JSON Schema: conversion, recursion, and validation
Schema Studio converts Apache Thrift structs to JSON Schema and checks sample JSON against the result. Use the browser editor for a one-off conversion, or the TypeScript SDK for scripts and CI.
Online conversion: required versus optional fields
Paste the following Thrift IDL into the left editor. The generated JSON Schema appears on the right.
struct User {
1: required string name
2: optional string email
}
Abbreviated output: only name is listed in required.
{
"type": "object",
"properties": {
"name": { "type": "string" },
"email": { "type": "string" }
},
"required": ["name"]
}
Convert recursive structs: $ref inside a list
Select the recursive-reference example in the playground. The list’s items.$ref points to the struct’s $id rather than expanding the struct indefinitely. A nested type must still be a string.
The SDK snippets use the current repository build. The npm 0.0.5 release is an older build; do not use it for the recursion and TypeBox 1 snippets below.
From the repository root, run the commands below with Node.js 24.22.2 and pnpm 12.21.0. After changing into the playground directory, save either snippet as example.mjs and run node example.mjs.
pnpm install --frozen-lockfile
pnpm build
cd app/parser-view
import { parseThriftToJsonSchema } from '@trasm/thrift-jsma'
const idl = `
struct FlexFilter {
1: required string type
2: optional list<FlexFilter> sub_conditions
}
`
const schema = JSON.parse(parseThriftToJsonSchema(idl))
const child = schema.properties.sub_conditions.items
console.log(child.$ref === schema.$id) // true
Validate JSON with TypeBox 1
parseThriftToJsonSchema() returns JSON text; parseThriftToTypeBox() returns a schema object you can pass to TypeBox.
import { parseThriftToTypeBox } from '@trasm/thrift-jsma'
import { Compile } from 'typebox/compile'
const idl = 'struct User { 1: required string name }'
const schema = parseThriftToTypeBox(idl)
if (!schema) throw new Error('No schema generated')
const validator = Compile(schema)
console.log(validator.Check({ name: 'Ada' })) // true
console.log(validator.Check({ name: 7 })) // false