JSON → Scala 3 & 2

JSON to Scala 3 & Scala 2 Case Class Generator

Transform JSON payloads into type-safe Scala case classes with optional Circe, Play JSON, or zio-json codecs and encoders.

Presets:
Root:
Package:
5 Classes32 FieldsDepth: 2
Input
package com.example.models

import java.time.Instant

import io.circe._
import io.circe.generic.semiauto._
import io.circe.syntax._

final case class Customer(
  customerId: String,
  email: String,
  fullName: String,
  loyaltyTier: String,
  registeredAt: Instant
) derives Codec.AsObject

final case class ShippingAddress(
  street: String,
  city: String,
  state: String,
  postalCode: String,
  country: String
) derives Codec.AsObject

final case class LineItem(
  sku: String,
  title: String,
  unitPrice: BigDecimal,
  quantity: Int,
  taxRate: BigDecimal,
  inStock: Boolean
) derives Codec.AsObject

final case class Payment(
  transactionRef: String,
  method: String,
  isAuthorized: Boolean,
  paidAt: Instant
) derives Codec.AsObject

final case class OrderPayload(
  orderId: String,
  orderNumber: String,
  customer: Customer,
  shippingAddress: ShippingAddress,
  lineItems: List[LineItem],
  subtotal: BigDecimal,
  taxAmount: BigDecimal,
  totalAmount: BigDecimal,
  currency: String,
  payment: Payment,
  discountCode: Option[String] = None,
  notes: String
) derives Codec.AsObject
5
Case Classes Inferred
32
Total Fields & Properties
Level 2
Max AST Hierarchy Depth

Zero-Knowledge Local Execution

All data processing, parsing, and compilation execute strictly inside your local browser memory. Zero external server uploads.

Sub-Millisecond AST Engine

All data payloads remain strictly local with zero external server communication.

Production Ready Export

Clean, optimized output formats ready for immediate deployment.

Technical Reference & Architecture Guide

JSON to Scala 3 & Scala 2 Case Class Generator — Reference Guide

Transform JSON payloads into type-safe Scala case classes with optional Circe, Play JSON, or zio-json codecs and encoders.

Key Parameters & Controls

Target Scala VersionEnum (Scala 3 | Scala 2.13)

Determines the generation syntax, enabling Scala 3 derives clauses or Scala 2 implicit companion codecs.

Default: Scala 3
JSON Codec LibraryEnum (Circe | Play JSON | zio-json | None)

Framework used to synthesize JSON serialization and deserialization codecs, decoders, and encoders.

Default: Circe
Root Class NameString

The identifier for the top-level case class representing the root JSON object payload.

Default: RootResponse
Null & Optional FieldsEnum (Option[T] | Strict T)

Wraps nullable JSON attributes and missing array elements in Scala Option[T] for null-safe access.

Default: Option[T]

Pro Tips & Best Practices

Scala 3 Derives Keyword

Targeting Scala 3 with zio-json or Circe generates clean 'case class User(...) derives JsonCodec' statements, eliminating boilerplate implicit companion object definitions.

Reserved Keyword Escaping

JSON keys matching reserved Scala keywords such as 'type', 'val', or 'object' are automatically escaped with backticks (e.g., `type`: String) to maintain compiling AST definitions.

Deeply Nested Sub-Models Extraction

Nested JSON trees are recursively analyzed and extracted into independent, modular companion case classes ordered from leaf nodes up to the root model.

Common Gotchas & Troubleshooting

Heterogeneous JSON Array Inconsistencies

When array items have varying fields, the generator merges all discovered keys and marks missing attributes as Option[T] to guarantee unmarshalling success.

Invalid Identifier Characters in JSON Keys

Keys with hyphens or special symbols (e.g., 'content-type') are converted to camelCase with corresponding @JsonKey or @jsonField mapping annotations.

Frequently Asked Questions

What is the difference between Scala 3 and Scala 2 outputs?▼

Scala 3 uses concise 'derives' clauses and optional indentation syntax, whereas Scala 2.13 generates implicit val decoders and encoders inside companion objects.

Which JSON serialization libraries are supported?▼

The generator natively supports Circe (io.circe.generic), zio-json, Play Framework JSON (play.api.libs.json), and plain vanilla case classes with zero external dependencies.

How are integer and floating-point JSON numbers mapped to Scala types?▼

Numbers without decimal points are mapped to Int or Long depending on value magnitude, while fractional numbers default to Double or BigDecimal for precise financial math.

Is my JSON payload uploaded to external servers?▼

No. The AST parsing and case class generation run 100% locally in your browser using pure client-side WebAssembly and JavaScript with zero network egress.

Related Tools & Utilities

All Tools →