JSON to Java Converter
Convert JSON to Java POJO classes for Java development
JSON Input
Java Output
What Is JSON to Scala?
Scala uses case classes with Circe or spray-json for JSON serialization. This tool generates Scala case classes from your JSON structure so you can parse API responses with Circe's decode or spray-json's JsonFormat. The JSON specification defines the input format.
Conversion runs in your browser. Set the class name and package in the config. Nothing is sent to a server. Add Circe or spray-json to your build.sbt or pom.xml to use the generated case classes.
How to Use This Tool
Paste or Upload JSON
Paste your JSON into the left editor or upload a file. Use the config panel to set the root Class Name and Package. The more representative your sample, the better the generated structure.
Review the Generated Case Classes
The right panel shows Scala case classes. Add Circe's import io.circe.generic.auto._ for automatic derivation, or spray-json's JsonFormat. Use decode[YourType](json) (Circe) or json.convertTo[YourType] (spray-json) to parse. Validate JSON first with JSON Validator if needed.
Copy or Download
Use Copy or Download. For formatting JSON first, use the JSON Formatter. For validation, use the JSON Validator.
JSON to Scala Examples
Here is an example of generating Scala case classes from a JSON object.
Example: Subscriber record
JSON input:
Generated Scala output:
When JSON to Scala Helps
When building Akka HTTP, Play, or Spark applications that consume REST APIs, you need typed case classes for the response payload. Pasting a sample response here gives you Scala types you can use with Circe, spray-json, or Play JSON. Manually writing case classes for complex nested JSON is tedious; this tool infers the structure from your sample.
For pulling out specific values from large responses first, use the JSON Path tool. For schema validation, use the JSON Schema Generator. Circe and spray-json are the most popular JSON libraries in the Scala ecosystem.
Frequently Asked Questions
Option for optional fields?
Use Option[T] for optional JSON fields. Circe and spray-json handle null and missing keys. Without Option, missing fields will cause a decoding error.
Circe vs spray-json?
Circe is more feature-rich and uses cats for error handling. spray-json is lighter and part of the Akka ecosystem. Both work with the generated case classes. Choose based on your project's dependencies.
Is my data private?
Yes. Generation runs entirely in your browser. No JSON or code is sent to any server.
How do I add Circe derivation?
Add import io.circe.generic.auto._ for automatic encoder/decoder derivation. For custom key names, use @JsonKey("json_key") from circe-generic.
Can I use this with Play Framework?
Yes. Play has its own JSON library, but you can use Circe or spray-json alongside it. The generated case classes work with any JSON library that supports Scala types.
Related Tools
Circe. spray-json. JSON spec. RFC 8259. MDN.