Handling JSON with uPickle
Info: JavaScript is currently disabled, code tabs will still work, but preferences will not be remembered.
uPickle is a lightweight serialization library for Scala.
It includes uJson, a JSON manipulation library that can parse JSON strings, access or mutate their values in memory, and write them back out again.
uPickle can serialize and deserialize Scala objects directly to and from JSON. It knows how to handle the Scala collections such as Map
and Seq
, as well as your own data types, such as case class
s and Scala 3 enum
s.
Using Scala CLI, you can require the entire toolkit in a single line:
//> using toolkit latest
Alternatively, you can require just a specific version of UPickle:
//> using dep com.lihaoyi::upickle:4.1.0
In your build.sbt file, you can add the dependency on the Toolkit:
lazy val example = project.in(file("."))
.settings(
scalaVersion := "3.4.2",
libraryDependencies += "org.scala-lang" %% "toolkit" % "0.7.0"
)
Alternatively, you can require just a specific version of UPickle:
libraryDependencies += "com.lihaoyi" %% "upickle" % "4.1.0"
In your build.sc file, you can add the dependency to the upickle library:
object example extends ScalaModule {
def scalaVersion = "3.4.2"
def ivyDeps =
Agg(
ivy"org.scala-lang::toolkit:0.7.0"
)
}
Alternatively, you can require just a specific version of UPickle:
ivy"com.lihaoyi::upickle:4.1.0"