Skip to content

Instantly share code, notes, and snippets.

@Slakah
Created February 14, 2019 11:25
Show Gist options
  • Save Slakah/152d884a4a4b43ab2e21dd92244ffced to your computer and use it in GitHub Desktop.
Save Slakah/152d884a4a4b43ab2e21dd92244ffced to your computer and use it in GitHub Desktop.
Walk a JSON tree using Circe
import $ivy.{
`io.circe::circe-core:0.10.0`,
`io.circe::circe-generic:0.10.0`,
`io.circe::circe-parser:0.10.0`
}
import io.circe._, io.circe.parser._
def walk(js: Json, f: Json => Json): Json =
js.arrayOrObject(
f(js),
arr => Json.fromValues(arr.map(walk(_, f))),
obj => Json.fromJsonObject(obj.mapValues(walk(_, f)))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment