Skip to content
XUtilHub

JSON to Scala Case Class Generator

Convert JSON to Scala case classes with circe or Play JSON codecs. Option fields with defaults, Long vs Int detection and exact key mapping.

  • Free, no sign-up
  • Runs in your browser, nothing uploaded
Input
Code

About the JSON to Scala

Generate Scala case classes from JSON, with circe decoders and encoders or Play JSON formats in the companion objects. Field names match your JSON keys exactly.

Key features

  • Scala case classes from any JSON sample
  • circe semi-auto decoders and encoders, or Play JSON formats
  • Option[T] fields with None defaults
  • Int vs Long chosen from your values
  • Field names match JSON keys exactly (backticks where needed)
  • Companion objects with implicit codecs

Scala case classes from JSON

Scala services built on http4s, Akka HTTP, Pekko or Play typically decode JSON into case classes. Paste a sample and get case classes with codecs for circe or Play JSON.

Example

[
  { "user_id": 7, "name": "Ada", "nickname": "ada", "score": 4.5 },
  { "user_id": 8, "name": "Alan", "nickname": null, "score": 3 }
]
import io.circe.{Decoder, Encoder, Json}
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}

final case class User(
  user_id: Int,
  name: String,
  nickname: Option[String] = None,
  score: Double
)

object User {
  implicit val decoder: Decoder[User] = deriveDecoder
  implicit val encoder: Encoder[User] = deriveEncoder
}
val users = io.circe.parser.decode[List[User]](json)

Libraries

OptionCompanion object providesDecode with
circeDecoder + Encoderdecode[User](json)
Play JSONOFormat with default valuesJson.parse(json).as[User]
None—Bring your own codecs

Tips

  • camelCase fields: with circe-generic-extras, configure Configuration.default.withSnakeCaseMemberNames and rename fields freely.
  • Dates: change String to java.time.Instant; circe and Play both include codecs for it.
  • Big numbers: use BigDecimal for money.

Generating for the JVM in other languages? See JSON to Java and JSON to Kotlin.

How to use the JSON to Scala

  1. Paste your data into the input box, upload a file, or click Sample to try it out.
  2. Adjust the options above the editor if you need to (indentation, delimiter, and so on).
  3. The Scala appears instantly in the output panel. Any errors are shown with their line and column.
  4. Click Copy to copy the result, or Download to save it as a file.

Frequently asked questions

Why are field names not converted to camelCase?

circe's and Play's automatic codecs map fields by name, so keeping the JSON key guarantees correct decoding. Backticks make keys like `first-name` or `type` legal identifiers.

Which dependencies do I need for circe?

circe-core, circe-generic and circe-parser. Decode with io.circe.parser.decode[User](json).

Does it support Scala 3?

Yes. Case classes and the generated implicit vals compile on Scala 2.13 and Scala 3. In Scala 3 you can also use given instances or derives Codec.AsObject.

How are missing fields handled?

Fields that are null or missing in some items become Option[T] = None, and circe and Play both decode a missing Option field as None.

Is my JSON uploaded to a server?

No. All JSON tools run entirely in your browser, so your data never leaves your device.

Is there a size limit?

There is no fixed limit. Files of several megabytes work fine; very large files depend on your device's memory.

Do I need an account?

No. Every JSON tool is free and works without signing up.

Last updated:

Related JSON tools