Advertisement

JSON to Scala Class

Turn JSON into Scala case classes. Immutable models with inferred types, Option fields, List collections, and nested classes in one line each.

JSON input

Paste JSON, optionally name the root type, then generate.

Your Scala case class code will appear here.
Advertisement

Functional data modeling

Scala models data as immutable values, and case classes are the vehicle. The generator converts each JSON object level into a case class with Option for uncertainty and List for collections.

Pattern match friendly

Because case classes support destructuring, the generated models work naturally in match expressions, which is how Scala code usually consumes parsed JSON.

JSON to Scala Class FAQs

What is a case class?
A case class is Scala's concise data holder: the compiler generates equals, hashCode, toString, copy, and pattern matching support from the parameter list.
How are optional fields handled?
Fields that were null or missing become Option[T], which is Scala's explicit optional type and forces callers to handle absence.
How are arrays represented?
JSON arrays become List[T] with T inferred from the elements, the default immutable sequence in Scala.
How are nested objects handled?
Each nested object becomes its own case class, keeping the one line per type compactness that makes case classes pleasant.
Does this work with circe or spray-json?
Yes. Case classes are exactly what circe's generic derivation and spray-json's jsonFormat expect, so serialization needs only the standard boilerplate.
Advertisement