zygfryd / scala-zygf-jackshaft   0.2.3

Apache License 2.0 GitHub

Incremental (non-blocking) parsing for Scala JSON ASTs, based on jackson-core.

Scala versions: 3.x 2.13 2.12 2.11

jackshaft

Incremental (non-blocking) parsing for Scala JSON ASTs, based on jackson-core.

Supported ASTs: spray-json.

Supported Scala versions: 2.11, 2.12, 2.13, 3.0, 3.1.

Supported jackson-core versions: 2.10+.

Caution
Beta-quality software.

Provides

For each supported AST:

  • akka-http entity marshaller and unmarshaller for single JSON values and akka-stream streams

  • Regular String and InputStream/OutputStream parser and printer for completeness

Usage

Artifact
"net.zygfryd" %% "jackshaft" % "0.2.2"

Support for akka-http

Instead of the usual:

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._

use:

import zygf.jackshaft.spray.AkkaSprayJsonSupport._

Marshalling and unmarshalling of single values should work the same. Streaming multiple values however no longer uses the *EntityStreamingSupport classes, as these are designed to configure a framing protocol, which isn’t needed with native support for multiple values.

To unmarshal an entity as a stream of JSON values simply use:

entity(as[Source[JsValue, NotUsed]]) { ... }

By default jackshaft assumes a whitespace-separated format for multiple values, if you’d like to stream the contents of an array instead, define:

import zygf.jackshaft.conf._

implicit val config: JackshaftConfig = JackshaftConfig.default.copy(streamingMode = StreamingMode.Array)

Performance

This library is optimized for peak memory usage, by never building a string or byte array to contain the whole serialized JSON document.

Parsing performance is on average slightly above the default spray-json parser, and should use less memory for large JSON documents.

Printing performance is 20-50% lower than competing libraries, due to its non-blocking nature.

TODO

  • optimize

  • add more ASTs

  • add more streaming IO frameworks