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. |
For each supported AST:
-
akka-http
entity marshaller and unmarshaller for single JSON values andakka-stream
streams -
Regular
String
andInputStream/OutputStream
parser and printer for completeness
Artifact |
"net.zygfryd" %% "jackshaft" % "0.2.2" |
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)
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.