These are chat archives for argonaut-io/argonaut

Jun 2016
Jun 14 2016 16:27
Is there a way to traverse into an array, such that all elements are descended into?
For example, if I had: {"arr":[{"root":{"a":"1"}},{"root":{"a":"2"}},{"root":{"a":"3"}}]}
Is there a way to return a list of all "a" elements?
I don't see anything in cursor that would allow that, but I was hoping for some kind of downArrayFields type operator
For comparison: in play-json you can go (Json.parse(str) \\ "a")
and \\ does a deep traversal returning a list of all "a" elements
Jun 14 2016 16:48
Only way I've found so far is this
(json.acursor --\ "arr").as[List[Json]] { x => (x.acursor --\ "root" --\ "a").as[String].value.get }
Julien Truffaut
Jun 14 2016 18:40
@aishfenton you can use JsonPath
Jun 14 2016 19:57
Thanks @julien-truffaut
I'll give that a go
Julien Truffaut
Jun 14 2016 19:59
@aishfenton np it is only available in 6.2-M2
Jun 14 2016 20:09
Still curious to know if there's a cleaner way to write what I had using the cursor stuff
here's the best I've come up with
for { 
    arr <- (json.acursor --\ "arr").as[List[Json]].value.get
    a = (arr.acursor --\ "root" --\ "a").as[String].value.get
  } yield a
Is that the most idiomatic approach in this case (assuming cursors are used) ?
The .value.get kinda urk me
But there's no straight .get on the DecodeResult.
In this case I expect the parsing to always pass, so would be nice if there was a shortcut option to just get the underlying value (and throw exception if decoding failed)
Julien Truffaut
Jun 14 2016 20:13
I am not sure how to use cursor for that case
btw I am thinking about submitting a talk to scalax about JsonPath