1

In the below JSON I am trying to find a condition.Where I want the result only if OrderNumber is not empty or null.

Conditions I have tried. But havent worked for me are:

> $..Item[?(@.OrderNumber)]
> $..Item[?(@.CurrentOrder.OrderNumber)]

Any suggestions will be appreciated. I am testing my queries here https://jsonpath.curiousconcept.com/

{
        "Response": {
            "ID": "123456",
             "Items": {
                "Item": [
                    {                       
                        "CurrentOrder": {
                            "OrderNumber": "123",
                            "Status": ""
                        }
                    }
                ]
            }
        }
    }
2

1 Answer 1

1

$..Item[?(@.CurrentOrder.OrderNumber)] is the correct JSONPath for your case.

The tool you used is known to not working correctly. See for example this question.

I have test above query with JSONPath Online Evaluator and for JSON

{
    "Response": {
        "ID": "123456",
        "Items": {
            "Item": [
                {
                    "CurrentOrder": {
                        "OrderNumber": "123",
                        "Status": ""
                    }
                },
                {
                    "CurrentOrder": {
                        "OrderNumber": "456",
                        "Status": ""
                    }
                },
                {
                    "CurrentOrder": {
                        "Status": ""
                    }
                }
            ]
        }
    }
}

it gives correct result:

[
  {
    "CurrentOrder": {
      "OrderNumber": "123",
      "Status": ""
    }
  },
  {
    "CurrentOrder": {
      "OrderNumber": "456",
      "Status": ""
    }
  }
]
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.