I'm looking for a most elegant way to traverse a list of objects with multiple fields in Json with circe optics.
Let's say we have this sort of JSON:
[
{
"key1": "one",
"key2": "two"
},
{
"key1": "three",
"key2": "four"
}
]
and we have a case class case class Entity(key1: String, key2: String)
So I want to find the most elegant and sleek way to traverse this JSON and create a list of case objects in the end.
I know that I can use each: root.each.key1.string.getAll(json)
, but how would I build a lens that will give me a traversable tuple (?) or something that I could put into for comprehension. I can probably combine lenses somehow.
There's already a question like that (how to parse un Array of object with Circe) but it has only one field in each object.
Recently I was also trying to solve a very similar problem: I wanted to implement with
circe-json
what would be the equivalent of the followingjq
line:The closest I got was this: