jsondecode.com logo

JSON to Scala Case Class with Circe Codec — Free Online

Convert JSON to a Scala case class with circe automatic codec derivation or play-json Format using AI. Handles nested types and Option fields. Free, no sign-up.

JSON to BigQuery Schema Converter — Free Online ToolJSON to React Flow Diagram — Convert JSON Online FreeJSON to Go Struct with BSON Tags — Free Online ToolJSON to TypeScript Interface Generator — Free OnlineJSON to YAML Converter — Convert JSON to YAML OnlineJSON to CSV Converter — Export JSON Array to CSV FreeJSON to Python Dataclass Generator — Free Online ToolJSON to SQL INSERT Statement Generator — Free OnlineJSON to Markdown Table Converter — Free Online ToolJSON to XML Converter — Convert JSON to XML Online FreeJSON to HTML Table Converter — Free Online ToolYAML to JSON Converter — Convert YAML to JSON Online FreeXML to JSON Converter — Convert XML to JSON Online FreeJSON to JSON Schema Generator — Free Online ToolJSON to GraphQL Schema Generator — Free Online ToolRuby to JSON Converter — Convert Ruby Hashes to JSON OnlineJSON to C# Class Generator — Free Online ToolJSON to Java Class (POJO) Generator — Free Online ToolJSON to Kotlin Data Class Generator — Free Online ToolJSON to Rust Struct Generator — Free Online ToolJSON to PHP Array Converter — Free Online ToolCSV to JSON Converter — Free Online ToolJSON to Dart Class Generator — Free Online ToolJSON to Swift Struct (Codable) Generator — Free OnlineJSON to Terraform HCL Variables Converter — Free OnlineJSON to Mongoose Schema Generator — Free Online ToolJSON to Prisma Schema Model Generator — Free OnlineJSON to Protocol Buffer (proto3) Generator — Free OnlineJSON to TOML Config Format Converter — Free Online ToolTOML to JSON Converter — Convert TOML to JSON Online FreeJSON to Apache Avro Schema Generator — Free Online ToolJSON to OpenAPI 3.0 Schema Component — Free Online ToolJSON to R Data Frame Code Generator — Free Online ToolJSON to Lua Table Syntax Converter — Free Online ToolJSON to Zod Schema (TypeScript) Generator — Free OnlineJSON to PowerShell Hashtable Converter — Free Online Tool

JSON to Scala Case Class with Circe Codec — Free Online

About JSON to Scala Case Class with Circe Codec — Free Online

JSON to Scala Case Class converts a JSON object into Scala case class definitions with circe or play-json codec derivation, mapping JSON types to their Scala equivalents. Developers use it to scaffold typed domain models from API responses in Scala backend services, Spark jobs, or Akka-based applications without writing repetitive boilerplate.

JSON to Scala Type Mapping

JSON TypeScala TypeNotes
stringString
integerInt / LongUse Long for values > 2^31
floatDouble / FloatDouble preferred for precision
booleanBoolean
nullOption[T]Nullable fields wrapped in Option
arrayList[T] / Seq[T]T inferred from element type
objectNested case classNew case class generated
ISO date stringString or java.time.InstantAdd custom codec for Instant

Scala JSON Library Comparison

Featurecirceplay-jsonspray-jsonupickle
Derivation styleAutomatic (semiauto/auto)Format.apply macrojsonFormat macroReadWriter derive
Cats/FP integrationNativeNoNoNo
Error handlingDecodingFailureJsErrorDeserializationExceptionAbortException
Akka HTTP supportakka-http-circeplay-json nativenativeakka-http-upickle
Scala 3 supportYesYesPartialYes

Frequently Asked Questions

How do I decode JSON to a Scala case class with circe?

Add io.circe:circe-generic and io.circe:circe-parser to your build.sbt. Import io.circe.generic.auto._ for automatic derivation. Then: import io.circe.parser._; parse(jsonString).flatMap(_.as[MyCaseClass]). The result is Either[Error, MyCaseClass] — use fold or getOrElse to handle errors.

How do I handle Option fields in Scala JSON deserialization?

Wrap nullable fields with Option[T]: val email: Option[String] = None. With circe, Option fields are automatically treated as optional — missing JSON keys produce None and present keys produce Some(value). This avoids NullPointerExceptions for fields that may be absent in the API response.

What is the difference between circe auto and semiauto derivation?

With auto derivation (import io.circe.generic.auto._), codecs are derived implicitly for all case classes in scope. With semiauto (import io.circe.generic.semiauto._), you explicitly call deriveDecoder[T] and deriveEncoder[T], giving more control and avoiding accidental derivation. Semiauto is recommended for production to keep compile times manageable in large codebases.

How do I serialize a Scala case class to JSON with circe?

Import io.circe.syntax._ and call caseClassInstance.asJson to get a Json value, then call .noSpaces or .spaces2 for the string output. Example: import io.circe.syntax._; val json = MyClass("Alice", 30).asJson.spaces2. The Encoder instance must be in scope via auto derivation or deriveEncoder[MyClass].

How do I map snake_case JSON keys to camelCase Scala fields?

With circe, use a custom configuration: implicit val config: Configuration = Configuration.default.withSnakeCaseMemberNames; then @ConfiguredJsonCodec case class MyClass(userId: String). With play-json, configure a custom Reads that maps each snake_case key to its camelCase equivalent. Both approaches let Scala code use idiomatic camelCase while the JSON stays snake_case.

If jsondecode.com saved you time, share it with your team

Free forever. No ads. No sign-up. Help other developers find it.