JSON Schema → Luau Type Converter (Rust) #2093
amirfarzamnia
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
JSON Schema → Luau Type Converter (Rust)
I built a Rust-based converter that takes a JSON Schema file and produces Luau type definitions. It’s intended for standard Luau, not just Roblox, and avoids assuming any engine-specific environment. If you’re using Luau in tooling, CLIs, game engines, or embedded environments, this should work out of the box.
The goal was simple: preserve as much of JSON Schema as Luau’s type system can reasonably represent, while keeping the output clean and predictable.
What it supports
Full JSON Schema primitives (string, number, integer, boolean, null)
Objects, arrays, enums, const
$ref,definitions,$defs(always exported, never inlined)allOf,anyOf,oneOfRequired vs. optional semantics
Constraints preserved as Luau comments:
@minimum,@maximum,@pattern,@minItems, etc.CLI + library API
Clear, type-safe error reporting
Example
Input Schema:
{ "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "number", "minimum": 0, "maximum": 120 } }, "required": ["name"] }Generated Luau:
CLI usage
json-schema-to-luau schema.json -o types.luau cat schema.json | json-schema-to-luau - json-schema-to-luau schema.json --type-name MyTypeLibrary usage
Design notes
number.$refs are intentionally unsupported.allOfmerges object properties if present; otherwise becomes an intersection.These behaviors are documented in the README.
Installation
Crate:
CLI:
Repo
https://github.com/amirfarzamnia/json-schema-to-luau
Beta Was this translation helpful? Give feedback.
All reactions