How can an extension method be written to remove all keys with a null value from an Argonaut Json object:
I tried this:
package object Extensions {
implicit class JsonExtensions(val json: Json) extends AnyVal {
def removeNulls: Json = {
json.withObject(j => JsonObject.from (j.toMap.filter(!_._2.isNull).toList))
}
}
}
but it only seems to be removing keys with null values at the top level of the Json object...
Argonaut supports this internally, you can use PrettyParams to do what you're after:
def removeNulls: Json = {
json.pretty(PrettyParams.nospace.copy(dropNullKeys = true)).toJson
}
Hope this covers your question!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With