What is Crystal?
Crystal is a statically typed, compiled language with a syntax inspired by Ruby — readable and expressive, but with type inference, native binaries, and performance comparable to C. It ships with a JSON module in the standard library that handles parsing and serialization with first-class language support.
How does JSON::Serializable work?
JSON::Serializable is a Crystal module you include in a class. At compile time it inspects the property declarations and generates from_json and to_json methods that map each JSON key to its corresponding property. Combined with Crystal’s type system, type errors at deserialization become compile-time errors.
How are nullable fields handled?
Mark a property nullable with the union type syntax: property name : String? — equivalent to String | Nil. The generator emits non-nullable types based on the sample (since the field was present); add ? after the type if you know the field is sometimes missing or null.
How are nested JSON objects modelled?
Each nested object becomes its own Crystal class that also includes JSON::Serializable. The parent class declares the property as the nested class type; deserialization recurses automatically because the nested class also has from_json generated.
How are JSON arrays handled?
A JSON array becomes Array(T) where T is inferred from the first element. Arrays of strings become Array(String); arrays of objects become Array(ChildClass). For arrays of mixed types use Array(JSON::Any) after generation.
What about JSON.mapping?
JSON.mapping was the older macro-based approach (Crystal pre-0.32). Modern Crystal (0.32+) prefers JSON::Serializable as a module include — cleaner syntax, better composition with other modules, and identical runtime behavior. The generator emits JSON::Serializable; if you target a legacy codebase, swap to JSON.mapping by hand.
Is the JSON uploaded to your servers?
No. Conversion runs entirely in your browser via JavaScript. Open DevTools → Network and click Convert — no requests are made. Pasting JSON containing tokens or proprietary data never leaves your machine.
How do I deserialize the generated classes?
Call Root.from_json(json_string) — the class method is generated by JSON::Serializable. Serialize back with my_root.to_json. For nested classes the method recurses automatically. Errors are raised as JSON::SerializableError at compile time when types do not match the schema.