import json._
@accessor case class Book(name: String, pages: Int, chapters: Seq[String])
Book("Making JSON Easy in Scala", 2, List("Getting Started, Fast", "Getting Back to Work")).js
res0: json.JObject =
{
"name": "Making JSON Easy in Scala",
"pages": 2,
"chapters": ["Getting Started, Fast", "Getting Back to Work"]
}
Compile time JSON marshalling of primitive values, case-classes, basic collections, and whatever you can imagine for scala, scala-native and scala-js.
- Extensible accessor API. Serialize any type you want.
- Provides a useful JS-like AST for intermediate JSON data.
- Implicit accessors that chain to resolve Higher-Kind types (e.g.
Option[T]
). - Uses default fields correctly.
- Preserves object field order.
- Rich field exceptions with field names (all field errors, not just the first), perfect for form validation.
- Ability to use non-string key types in a Map (for key types that serialize to JString).
- Enables use of normal looking scala structures with any previously existing JSON API.
- Produces pretty and human readable JSON from normal scala types.
- Supports scala-js so you can extend your models to the web.
- Supports scala-native so you can take your models everywhere else (requires jansson, available through apt, brew, etc).
- Enables you to create readable APIs that match existing/specific class structure.
- Exposes rich compile-time type info, more run-time type data than reflect could ever provide.
- Uses existing scala collection CanBuildFrom factories to support buildable collections.
- Provides support for unknown types (Any) via 'pickling' with a run-time class registry.
- Support for scala 2.10.x, 2.11.x, 2.12.0-M3.
- Support for scala-js 0.6.x.
- Support for scala-native 0.1.x.
- Usage and Examples - Getting started with basic usage and examples.
- Accessors - Accessors are the compile-time constructs that allow you to go from a JValue to a scala type and back.
- Registry - The Accessor Registry allows you to pickle registered types from untyped (Any) data.
- Enumerator - Allows enumerated case object values of a sealed trait (useful for map keys).
- EpochDeadline - Clone of scala's Deadline that serializes to numeric Unix epoch time.
- Migration - Uses a version field in JSON to transform old schemas to new ones.
- Scaladocs
resolvers += "mmreleases" at "https://artifactory.mediamath.com/artifactory/libs-release-global"
//scala
libraryDependencies += "com.mediamath" %% "scala-json" % "1.1"
//or scala + scala-js/scala-native
libraryDependencies += "com.mediamath" %%% "scala-json" % "1.1"
//for @accessor annotation support
resolvers += Resolver.sonatypeRepo("releases")
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)