JSON to Crystal Converter

Generate Crystal JSON::Serializable classes from sample JSON when you want typed parsing and annotation-ready model scaffolding for Crystal apps.

How to use

  1. Paste a representative JSON payload that matches the API response, config file, or event body your Crystal code handles.
  2. Review the generated classes, `include JSON::Serializable` blocks, and inferred field types for nested content.
  3. Copy the output into your Crystal project and refine nilable fields, module names, or custom converters as needed.

Benefits

  • Produces Crystal models that are ready to align with JSON::Serializable parsing workflows.
  • Cuts down on manual property and annotation authoring for nested JSON payloads.
  • Helps Crystal services and CLI tools move from loose hashes into typed transport models quickly.

Best use cases

  • Crystal web apps that want typed request or response models from real JSON samples.
  • CLI tools and background jobs that deserialize JSON config or API payloads repeatedly.
  • Teams standardizing on JSON::Serializable instead of handwritten parse logic.

Crystal model tips

  • Review nilable fields carefully if real payloads omit keys that are present in your example data.
  • Keep JSON key rename annotations in place when the source payload uses names that do not fit Crystal conventions.
  • Use generated models as transport types first, then wrap them in richer domain objects if the app needs stricter behavior.

Sample JSON

{
  "id": 101,
  "name": "Ada Lovelace",
  "active": true,
  "roles": ["admin", "editor"],
  "profile": {
    "email": "ada@example.com",
    "score": 9.8
  }
}

Sample Crystal output

require "json"

class UserModel
  include JSON::Serializable

  property id : Int32
  property name : String
  property active : Bool
  property roles : Array(String)
end

FAQ

Why choose the Crystal route instead of Ruby output?

Choose the Crystal route when you want compiled, statically typed model scaffolding with JSON::Serializable support. Choose Ruby when your target stack is Rails or a dynamic Ruby service instead.

Does the Crystal route preserve nested JSON structure?

Yes. Nested objects and arrays are expanded into additional Crystal model types so larger payloads stay typed and readable.