formatjson.pro
Validate, pretty-print or minify JSON in your browser — nothing is uploaded.

JSON to Scala Case Class

Runs entirely in your browser — your JSON is never uploaded to a server. No ads injected into the output, no sign-up, no sample data kept.

How to generate a Scala case class from JSON

  1. Paste your JSON. Paste one representative JSON object into the box above.
  2. Generate the case class. Click Generate Scala case class. The tool infers a type for every field and emits a case class for the root and each nested object.
  3. Decode with a library. Add circe or play-json, derive a decoder for each case class, and call decode[Root] on your JSON string.

How the type mapping works

Each JSON value maps to a Scala type: a whole number becomes Long, a decimal becomes Double, a string becomes String, true/false becomes Boolean, and null becomes Option[Any]. Arrays become List[T] using the type of the first element.

Arrays and nested objects

Every nested object gets its own case class so the result is a clean, immutable model. Wrap fields that may be absent in Option[T]. The order places nested classes after the root.

Using the result

Decode with a library such as circe or play-json: derive a decoder for each case class and call decode[Root](json).

FAQ

Which JSON library should I use?

These plain case classes work with circe, play-json, jsoniter, or json4s. Most can derive codecs automatically from the case class.

How do I handle optional fields?

A single sample cannot show which keys are missing elsewhere. Change the field type to Option[T]; most decoders map a missing or null key to None.

Why Long and Double?

JSON has one number type. The tool picks Long for whole numbers and Double for decimals. Narrow to Int or BigDecimal where the real range is known.