0

I have the following json:

{
    "books": [
        {
            "id": 1,
            "name": "República Brasileira. de Deodoro a Bolsonaro - 2° Edição",
            "writers": [
                {
                    "name": "Paulo Ghiraldelli Jr.",
                    "id": 1
                },
                {
                    "name": "Mariangela",
                    "id": 2
                }
            ]
        },
        {
            "id": 2,
            "writers": [
                {
                    "name": "Ilan Lapyda",
                    "id": 3
                }
            ]
        }
    ]
}

And I'm writing a JSONPath expression to find books that was written by "Mariangela". I have tried the following expression:

$.books[?(@.writers[*]['name']=='Mariangela')]

But I'm receiving "Invalid X-JSON-Path expression passed". What have I done wrong?

user2919910
  • 575
  • 1
  • 7
  • 17

1 Answers1

0

My bad you are right, is this one so:

$.books[?(@.writers[?(@.name=='Mariangela')]).name]
desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • Your expression will return the writer, but what I'm trying to accomplish is to return books written by a certain person. – user2919910 May 26 '23 at 12:12
  • Sorry, I edited it – Borja Navarro May 26 '23 at 15:56
  • It makes sense your expression but when I submit this to jsonpath.com tester, I got the error ```jsonPath: Unexpected token '?': _$_v.writers[?(_$_v.name=='Mariangela' ``` – user2919910 May 26 '23 at 18:18
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 27 '23 at 12:06