Search code examples
jsonjsonpathjsonparserjson-patch

Like expression in JSON Path


I have a JOSN some thing like this

{
    "Room" :{
    "Book" : 
     {
        "name" : "abc"
     },

    "Book1": 
     {
       "name" : "xyz"
     },

    "Book3": 
    {
      "name" : "abc123"
    },

    "Tv" : 
    {
      "name" : "zyc"
    },

    "audio": 
    {
      "name" :"sound ++"
    }
    }
}

From this JSON I want to filter out all book elements("book","book1","book2") using JSONPATH

As I got to know in in JSONPATH we do not have any "Like" type syntax , but we can do that by using regex.

I tried with this

$.Room[?(/^.*book.*$/i.test(@.Room))]

But this expression return nothing from the JSON.

Can any one help me out in this...


Solution

  • Maybe this link will be helpful for you . Check the table $..book[?(@.author =~ /.*Tolkien/i)]. This expression brings All books whose author name ends with Tolkien (case-insensitive) --> Modify it for yours