I am in the process of switching from json to avro format and all my unit tests are still expecting json. I can convert the newly avro files to json but the schema is embedded. For example:
val j = """{"field1": "someString", "field2": 1607359485}"""
// now becomes:
val jAvro = """{"field1": {"string":"someString"}, "field2": {"long":1607359485}}"""
I want, momentarily, to remove the schema from jAvro
. Parsing it is not a problem:
import play.api.libs.json.{ JsObject, Json }
Json.parse(jAvro).as[JsObject]
But how can I programmatically remove all the schema information, so that I get the same outpout as Json.parse(j).as[JsObject]
?
EDIT
Thanks for your answers. I forgot to mention that the level of intricacy might be superior to my example.
I could have:
val jAvro = """{"field1": {"string":"someString"}, "field2": {"long":1607359485}, "field3":{"SomeObject":{"subfield1":{"int":11},"subfield2":{"string":"someString2"}}}"""
and I would like to extract:
val j = """{"field1":"someString", "field2":1607359485, "field3":{"subfield1":11,"subfield2":"someString2"}}"""
You can try something like:
Code run at Scastie.