JSON-path-- selecting parent operator?

Viewed 555

This question seems straightforward but perhaps doesn't exist.

I'm using native Jsonpath, not additional javascript.

Say I have the following

{
  "books":[{
     "author":"Twain",
     "titles":[
        {"name":"Huck Finn"}, 
        {"name":"Tom Sawyer"}, 
        {"name":"King Arthur"}]
    },
    {
     "author":"Dickens",
     "titles":[
        {"name":"Two Cities"}, 
        {"name":"Hard Times"}, 
        {"name":"Great Expectations"}]
    }]}

To get a list of book title names, I would do the following jsonpath:

$.books[*].titles[*].name

To get a list of authors, I'd use the following jsonpath:

$.books[*].author

What I want to do ultimately is a jsonpath that produces an author for every book title. So it would in effect produce

Twain
Twain
Twain
Dickens
Dickens
Dickens

Is there a jsonpath that essentially is like

$.books[*].titles[*].name.(parent).(parent).author

--- go back up the chain, so to speak? Again, just want to use native jsonpath

Actually ... hmm .. looks like there is no parent operator in jsonpath. Maybe I just have to use javascript more -

0 Answers
Related