0

I have a JSON of type

{
    "time": {
        "updated": "Mar 8, 2022 11:21:00 UTC",
        "updatedISO": "2022-03-08T11:21:00+00:00",
        "updateduk": "Mar 8, 2022 at 11:21 GMT"
    },
    "disclaimer": "This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org",
    "chartName": "Bitcoin",
    "bpi": {
        "USD": {
            "code": "USD",
            "symbol": "$",
            "rate": "38,847.2041",
            "description": "United States Dollar",
            "rate_float": 38847.2041
        },
        "GBP": {
            "code": "GBP",
            "symbol": "£",
            "rate": "29,605.7650",
            "description": "British Pound Sterling",
            "rate_float": 29605.765
        },
        "EUR": {
            "code": "EUR",
            "symbol": "€",
            "rate": "35,645.1844",
            "description": "Euro",
            "rate_float": 35645.1844
        }
    }
}

I wanted to get all the values of the rate which are higher than 3000. I tried in below ways

List rateValue =  jsonPath.getList("bpi.findAll{it->it.[\*].rate_float> 3000}");
 and
List rateValue = jsonPath.getList("bpi.[\*].findAll{it->it.rate_float> 3000}");

Notes: I only wanted to use JSONPath

  • You can't do it b/c 2 reasons: 1. value of key `bpi` is object --> can't use `findAll` (`find` or `findAll` only apply for array). 2. value of `rate` is String --> can't use comparison operator `>`. – lucas-nguyen-17 Mar 09 '22 at 01:11
  • Thank you @lucas-nguyen-17, yes you are correct. If the bpi is an array then I could have get the values of rate by find or findall. How could I get any specific JSON key values if it's an Object, I only wanted to use JSONPath – swathi ravula Mar 09 '22 at 05:27
  • @lucas-nguyen-17 can you remove question as duplicate. I don't see any similarities in the link given, – swathi ravula Mar 09 '22 at 05:28
  • In your case, there is no way to use JsonPath in RA to solve the problem. The simple solution I can think of is using JsonPath jayway, then you can extract using path `$.bpi..rate`. I don't know how to reopen your question. You can create new question with different title. – lucas-nguyen-17 Mar 09 '22 at 05:41

0 Answers0