0

I'm using a JSON like this one

[
    [{
        "tool": "one",
        "products": [
            "Prod1",
            "Prod2",
            "Prod3",
            "Prod4",
            "Prod5",
            "Prod6"
        ],
        "count": 6
    }],
    [{
        "tool": "two",
        "products": [
            "Prod1",
            "Prod7",
            "Prod3",
            "Prod8",
            "Prod5",
            "Prod9"
        ],
        "count": 6
    }],
    {
        "tool": "three",
        "products": [
            "Prod10",
            "Prod70",
            "Prod30"
        ],
        "count": 3
    }
]

and I'd like to extract all the Prod* that are about the tool "one" so the list

"Prod1",
"Prod2",
"Prod3",
"Prod4",
"Prod5",
"Prod6"

and then the same about the tools "two" and "three".

I'm in troubles with the right filter to use to obtain the result.

Any suggestion will be appreciated and thank you in advance

1 Answer 1

1

$..[?(@.tool=="one")] should filter the node that you are interested. you can then access the products list using

$..[?(@.tool=="one")].products.*

Use https://jsonpathfinder.com/ to find the exact output path and then use https://jsonpath.com/ to try different jsonpath-expressions

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.