Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Cursor can descend into string as json #222

Open
newhoggy opened this issue Apr 5, 2016 · 4 comments
Open

Feature request: Cursor can descend into string as json #222

newhoggy opened this issue Apr 5, 2016 · 4 comments

Comments

@newhoggy
Copy link

newhoggy commented Apr 5, 2016

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
    }
@seanparsons
Copy link
Member

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.

@newhoggy
Copy link
Author

newhoggy commented Apr 5, 2016

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.

@seanparsons
Copy link
Member

I don't doubt it's out there, it's more that each edge case feature we support is more potential weight to maintain.

@tonymorris
Copy link
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants