1

I've following json -

{
"issues": [{
    "id": 200615,
    "custom_fields": [{
        "id": 166,
        "name": "Severity",
        "internal_name": null,
        "field_format": "list",
        "value": "Major"
    }, {
        "id": 167,
        "name": "Reproducibility",
        "internal_name": null,
        "field_format": "list",
        "value": "Always"
    }, {
        "id": 168,
        "name": "Resolution",
        "internal_name": null,
        "field_format": "list",
        "value": "open"
    }]
}]

}

Out of this json I want to get value of issues -> custome_fields -> value where id is 167 and expected value is - Always (167 can be at any position in json hence can't hardcode it)

Could you please how I can achieve the value?

jsonPath.get("issues[0].custom_fields[?(@.id == '167')].value[0]")

results into error -

java.lang.IllegalArgumentException: Invalid JSON expression:
Script1.groovy: 1: expecting EOF, found '[' @ line 1, column 50.
   Object.issues[0].custom_fields[?(@.id ==
Alpha
  • 13,320
  • 27
  • 96
  • 163

2 Answers2

0

I get the same error as you do and I don't know why.

However, you can achieve the same goal using findAll json path method like this:

issues[0].custom_fields.findAll { it.id == 167 }.value[0]

Prints out: Always

Fenio
  • 3,528
  • 1
  • 13
  • 27
  • 2
    Thanks! or we can `find` to get individual like `issues[0].custom_fields.find { it.id == 24 }.value` – Alpha Mar 28 '20 at 09:24
0

$.issues[0].custom_fields[?(@.id==167)].value

James Risner
  • 5,451
  • 11
  • 25
  • 47