Feature request: Cursor can descend into string as json
Would be nice if there was a combinator that can descend into a JSON string as if it were JSON. For example with the JSON:
{ "field": "\"{\"subField\": 1}" }
Be able to navigate a cursor like this:
c --\! "field" --\ "subField".as[Int]
Here's some example code as proof of concept:
implicit class ACursorOps(self: ACursor) {
def --\!(fieldName: String): ACursor = (self --\ fieldName).parsed
def parsed: ACursor = {
self.as[String].result match {
case Left((_, history)) =>
self.history.failedACursor(self.any.cursor)
case Right(text) =>
Parse.parse(text) match {
case Left(message) =>
self.history.failedACursor(self.any.cursor)
case Right(json) =>
self.history.acursor(json.cursor)
}
}
}
}
implicit class HCursorOps(self: HCursor) {
def --\!(fieldName: String): ACursor = (self --\ fieldName).parsed
}
Hmmm, that's interesting, I'm slightly worried it's satisfying a niche case but I'll keep this here for now and wont close it.
I encountered this kind of JSON when using AWS. If you have subscribe an SNS topic to an S3 bucket and then subscribe and SQS subscription to SNS, you will get JSON that looks like this.
I don't doubt it's out there, it's more that each edge case feature we support is more potential weight to maintain.
:+1: