0

I'm looking for a way to filter this JSON and retrieve only the cost when fid > 10

Working example, the parent prop is an array:

 [
    {
        "id": 1,
        "properties": {
            "parent": [
                {
                    "fid": 10,
                    "cost": 100
                }
            ]
        }
    },
    {
        "id": 2,
        "properties": {
            "parent": [
                {
                    "fid": 20,
                    "cost": 200
                }
            ]
        }
    },
    {
        "id": 32,
        "properties": {
            "parent": [
                {
                    "fid": 30,
                    "cost": 300
                }
            ]
        }
    }
]

JSONPath = $[*].properties.parent[?(@['fid']>10)].cost

result = [
  200,
  300
]

Not working example, the parent prop is now an object:

[
    {
        "id": 1,
        "properties": {
            "parent": {
                "fid": 10,
                "cost": 100
            }
        }
    },
    {
        "id": 2,
        "properties": {
            "parent": {
                "fid": 20,
                "cost": 200
            }
        }
    },
    {
        "id": 32,
        "properties": {
            "parent": {
                "fid": 30,
                "cost": 300
            }
        }
    }
]

JSONPath = $[*].properties.parent[?(@['fid']>10)].cost

The result is No match

1 Answer 1

3

try this

$[?(@.properties.parent.fid>10)].properties.parent.cost
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.