Back to articles
json2rs: Generate Struct Definitions from JSON, Without the Magic

json2rs: Generate Struct Definitions from JSON, Without the Magic

via Dev.toMojave Hao

I built a small CLI tool that converts JSON files into struct definitions for Rust, Python, TypeScript, Kotlin, and Java. It's called json2rs . The Problem You have a JSON file — maybe an API response, maybe a config schema — and you need to write struct/class definitions for it. Doing it by hand is tedious. Existing generators are often too clever: they guess, they infer, they silently produce something that almost compiles. I wanted something different. Design Philosophy Fail fast and loud. If the input JSON is malformed or ambiguous in a way that would produce bad output, the tool stops and tells you. No silent failures, no generated code that compiles but lies about your data. Not intelligent. json2rs does not try to infer whether two similar structures should be the same type. It does not guess optional fields. It does not merge anything. What it sees is what it generates. Output that reads like hand-written code. The goal is that you could have written the output yourself. No ext

Continue reading on Dev.to

Opens in a new tab

Read Full Article
34 views

Related Articles