Circe JSON for Tokenization
Printing
import io.circe.{Json, Printer}
val compact = Printer.noSpaces.print(json)
val pretty = Printer.spaces2.print(json)
Path-Based Navigation with ACursor
import io.circe.ACursor
def navigate(json: Json, path: String): Option[Json] = {
val cursor = path.split("\\.").foldLeft(json.hcursor: ACursor) { (c, part) =>
if (part.forall(_.isDigit)) c.downN(part.toInt)
else c.downField(part)
}
cursor.focus
}
Key Differences from Python json module
- circe uses
JsonADT instead of Python's dynamic types - No need for recursive
JsonValuetype alias -Jsonis already recursive - Printing via
Printerinstances rather thanjson.dumpskwargs