Skip to content

Instantly share code, notes, and snippets.

@josephpconley
Created February 25, 2014 12:34
Show Gist options
  • Save josephpconley/9207995 to your computer and use it in GitHub Desktop.
Save josephpconley/9207995 to your computer and use it in GitHub Desktop.
Convert JSON object into an empty JSON object
object JS {
def default(js: JsValue): JsValue = js match {
case JsObject(fields) => JsObject(fields.map(f => f._1 -> default(f._2)))
case JsString(s) => JsString("")
case JsArray(a) => JsArray()
case JsNumber(n) => JsNumber(0.0)
case JsBoolean(b) => JsBoolean(false)
case _ => JsString("")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment