Created
February 14, 2019 11:25
-
-
Save Slakah/152d884a4a4b43ab2e21dd92244ffced to your computer and use it in GitHub Desktop.
Walk a JSON tree using Circe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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