Skip to content

Instantly share code, notes, and snippets.

@erwan
Created January 9, 2018 16:13
Show Gist options
  • Save erwan/33481f148eaa3974dae8f6b38645b2bd to your computer and use it in GitHub Desktop.
Save erwan/33481f148eaa3974dae8f6b38645b2bd to your computer and use it in GitHub Desktop.
Map a functions to all Strings in circe
import io.circe._
import io.circe.syntax._
def mapStrings(json: Json)(f: String => String): Json = json.fold(
json, // null
_ => json, // boolean
_ => json, // number
str => f(str).asJson,
arr => arr.map(mapStrings(_)(f)).asJson,
obj => obj.mapValues(mapStrings(_)(f)).asJson
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment