gzoller / scalajack

Fast JSON parser/generator for Scala

GitHub

ScalaJack

license bintray Build Status Codacy branch grade Coveralls branch

ScalaJack is a very fast, seamless JSON serialization engine designed to require the minimum amount of help possible when serializing a class.

Advanced Features:

  • Handles tuples
  • 'Any' support
  • Handles default values for case class fields
  • Rich configuration of trait type hint/value
  • Supports value classes
  • Pluggable reader/render (for non-JSON encodings--CSV, MongoDB, and DynamoDB)

Use

ScalaJack is extremely simple to use.

Include it in your projects by adding the following to your build.sbt:

libraryDependencies ++= Seq("co.blocke" %% "scalajack" % "5.0.8")

If you want to use the optional MongoDB serialization support include this as well:

libraryDependencies ++= Seq("co.blocke" %% "scalajack_mongo" % "5.0.8")

DynamoDB helpers are available here:

libraryDependencies ++= Seq("co.blocke" %% "scalajack_dynamo" % "5.0.8")

ScalaJack is hosted on Bintray/JCenter now so if you're using sbt v0.13.9+ you should find it with no issues.

If you're on sbt v0.13.11 you may need to enable the bintray resolver in your build.sbt with

useJCenter := true

Now you're good to go! Let's use ScalaJack in your project to serialize/de-serialize a case class object into JSON:

import co.blocke.scalajack._

val sj = ScalaJack()
val js = sj.render( myCaseObj )  // serialization
val myObj = sj.read[MyCaseClass](js) // deserialization

Couldn't be simpler!

Features

Non-JSON Formats:

Benchmarks

Benchmark Score Error Units
Hand-written 28683.250 ± 3505.351 ops/s
ScalaJack 5.0 20632.580 ± 306.105 ops/s
Spray 10314.990 ± 120.898 ops/s
LiftJson 9313.326 ± 212.206 ops/s
ScalaJack 4.8.3 6525.699 ± 36.103 ops/s
Json4s 5840.046 ± 201.42 ops/s

Series 5

The entire ScalaJack engine and test suite was redesigned for 5.0. This new design streamlines processing tremendously while maintaining both flexibility and simplicity. In addition to reaching new levels of performance, a major design goal was to allow a flexible way to implement new serialization targets beyond JSON.

This project welcomes our newest team member and core committer, Adam Paynter! The design for ScalaJack 5's new engine was made possible by his thought leadership and sense of adventure.

We hope you'll enjoy using the latest ScalaJack!

Blöcke