0

I have a JSON file having customer data as below . Here I want to extract the custName & CustId where amount is greater than 10 . But I'm stuck as unable to get the desired jsonpath for extracting these values .

  "customers": [
    {
      "custId": 540,
      "custName": "John",
      "itemId": 647,
      "itemAmount": 3000
    },
    {
      "custId": 432,
      "custName": "Adrian",
      "itemId": 600,
      "itemAmount": 2000
    },
    {
      "custId": 541,
      "custName": "Smith",
      "itemId": 320,
      "itemAmount": 1200
    }
  ]
} 

I tried something like - $.customers[*].itemAmount which gave me a list of itemAmount but my objective is entirely different so looking for the jsonPath expression to get the desired data.

2 Answers 2

1

To get both fields for everything meeting the criterion:

$.customers[?(@.itemAmount > 10)]['custName','custId']

I recommend adding some records that do not meet the criterion to your sample so you can be sure it is working.

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

Comments

1

Try this:

custName when amount > 10 - $.customers[?(@.itemAmount > 10)].custName

custId when amount > 10 - $.customers[?(@.itemAmount > 10)].custId

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.