I have code which looks roughly like this:
val json: Json = parse("""
[
{
"id": 1,
"type": "Contacts",
"admin": false,
"cookies": 3
},
{
"id": 2,
"type": "Apples",
"admin": false,
"cookies": 6
},
{
"id": 3,
"type": "Contacts",
"admin": true,
"cookies": 19
}
]
""").getOrElse(Json.Null)
I'm using Circe, Cats, Scala, Circe-json, and so on, and the Parse call succeeds.
I want to return a List, where each top-level Object where type="Contacts", is shown in it's entirety.
Something like: List[String] = ["{"id": 1,"type": "Contacts","admin": false,"cookies": 3}","{"id": 3,"type": "Contacts","admin": true,"cookies": 19}"]
The background is that I have large JSON files on disk. I need to filter out the subset of objects that match a certain type=
value, in this case, type=Contacts
, and then split these out from the rest of the json file. I'm not looking to modify the file, I'm more looking to grep for matching objects and process them accordingly.
Thank you.