Skip to content

Giving incorrect results when the json path is nested #1043

@kavyaNamballa

Description

@kavyaNamballa

Sample Json:

`[

{
    "id": 1,
    "name": "Store A",
    "departments": [
        {
            "id": 10,
            "name": "Electronics",
            "products": [
                {
                    "id": 101,
                    "name": "TV",
                    "in_stock": true
                },
                {
                    "id": 102,
                    "name": "Laptop",
                    "in_stock": false
                }
            ]
        },
        {
            "id": 11,
            "name": "Clothing",
            "products": [
                {
                    "id": 201,
                    "name": "Shirt",
                    "in_stock": true
                },
                {
                    "id": 202,
                    "name": "Jeans",
                    "in_stock": true
                }
            ]
        }
    ]
},
{
    "id": 2,
    "name": "Store B",
    "departments": [
        {
            "id": 12,
            "name": "Grocery",
            "products": [
                {
                    "id": 301,
                    "name": "Milk",
                    "in_stock": false
                },
                {
                    "id": 302,
                    "name": "Eggs",
                    "in_stock": true
                }
            ]
        }
    ]
}

]`

// This should return only "Store B" but returns both stores

Object result = JsonPath.read(json, "$[?(@..products[?(@.id==302)])].name");
Expected: ["Store B"], Actual: ["Store A", "Store B"]

I've tried with this path also,

Object result = JsonPath.read(json, "$[?(@.departments[?(@.products[?(@.id==302)])])].name");
Expected: ["Store B"], Actual: ["Store A", "Store B"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions