Encoding to JSON
Serialize your data out.
Encoders Produce JSON
An Encoder[A] is the dual of a decoder: it turns a Scala value of type A into a Circe Json tree.
From there you serialize to a String for HTTP responses, logs, or storage.
The asJson Syntax
Import io.circe.syntax._ to get the .asJson extension method on any value that has an Encoder in scope.
Primitives and collections work immediately.
import io.circe.syntax._
println(42.asJson.noSpaces) // 42
println("hi".asJson.noSpaces) // "hi"
println(List(1,2,3).asJson.noSpaces) // [1,2,3]All lessons in this course
- Parsing JSON
- Decoding into Case Classes
- Encoding to JSON
- Custom Codecs