JSON to Crystal Class screenshot

JSON to Crystal Class

Turn a JSON sample into a Crystal class in your browser. Absent and null fields stay distinct, and nothing is uploaded.

Privacy First
0 Runs
Updated 2026-11-06
No upload
Instant
No signup

What the JSON to Crystal generator does

Each object becomes a class with typed properties, and JSON::Any is used for a field whose type varied. Crystal has no implicit null, so a key that is absent from some elements is declared with a trailing question mark and a nil default. The json require is emitted only when JSON::Any is actually used, so a document of plain strings and numbers produces a file with no dependencies at all.

How to use it

JSON to Crystal Class: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Crystal class below.

Worked example

Input:

{
  "orderId": "A-1001",
  "total": 129.99,
  "currency": "EUR",
  "paid": false,
  "customer": {
    "email": "[email protected]"
  },
  "lines": [
    {
      "sku": "X1",
      "qty": 2
    },
    {
      "sku": "X2",
      "qty": 1,
      "discount": 0
    }
  ]
}

Output:

# Generated from a JSON sample in the browser by AllTools — nothing was uploaded.
# Rename and adjust to taste; the shape is inferred from one example, not a schema.

class Root
  property order_id : String
  property total : Float64
  property currency : String
  property paid : Bool
  property customer : Customer
  property lines : Array(Line)
end

class Customer
  property email : String
end

class Line
  property sku : String
  property qty : Int32
  property discount : Int32? = nil
end

Why it runs in your browser

The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns Crystal class; reloading the page discards both.

Each object becomes a class with typed properties, and JSON::Any is used for a field whose type varied. Crystal has no implicit null, so a key that is absent from some elements is declared with a trailing question mark and a nil default. The json require is emitted only when JSON::Any is actually used, so a document of plain strings and numbers produces a file with no dependencies at all.

Turn a JSON sample into a Crystal class in your browser. Absent and null fields stay distinct, and nothing is uploaded.

How to use it

JSON to Crystal Class: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Crystal class below.

Why it runs in your browser

The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns Crystal class; reloading the page discards both.

What to Expect

Best for

  • Converting JSON to Crystal class when the data is already on screen.

What this tool keeps

  • Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere.

Sample input

{ "orderId": "A-1001", "total": 129.99, "currency": "EUR", "paid": false, "customer": { "email": "[email protected]" }, "lines": [ { "sku": "X1", "qty": 2 }, { "sku": "X2", "qty": 1, "discount": 0 } ] }

Sample output

# Generated from a JSON sample in the browser by AllTools — nothing was uploaded. # Rename and adjust to taste; the shape is inferred from one example, not a schema. class Root property order_id : String property total : Float64 property currency : String property paid : Bool property customer : Customer property lines : Array(Line) end class Customer property email : String end class Line property sku : String property qty : Int32 property discount : Int32? = nil end

Frequently asked questions

How do I use the json to crystal class?

JSON to Crystal Class: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Crystal class below.

Is my input uploaded?

No. The text is parsed on this page with JavaScript and is never posted to a server.

Is there a size limit?

Yes: 5 MB per run. Larger input is refused with a message rather than freezing the tab.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.