So I was using a json path syntax for the json below
{"documents": [
{
"id": 1231,
"doctType": "FFS",
"docValue": "3123123",
"isPrim": 0
},
{
"id": 1232,
"docType": "National Identity Card",
"docValue": "0000840317",
"isPrim": 1,
"resources": [
{
"id": 23893452,
"name": "national card"
},
{
"id": 52524055,
"name": "national card front"
},
{
"id": 4266737,
"name": "physical Form"
}
]
},
{
"id": 1233,
"docType": "National Identity 1234",
"docValue": "312312",
"isPrim": 1,
"resources": [
{
"id": 23893452,
"name": "national card back"
},
{
"id": 52524055,
"name": "national card front"
},
{
"id": 4266737,
"name": "physicalForm"
}
]
}
]}
Here I use the below mentioned json path
$.documents[?(@.isPrim==1)]
This returns the below output
[ { "id": 1232, "docType": "National Identity Card", "docValue": "0000840317", "isPrim": 1, "resources": [ { "id": 23893452, "name": "national card" }, { "id": 52524055, "name": "national card front" }, { "id": 4266737, "name": "physical Form" } ] }, { "id": 1233, "docType": "National Identity 1234", "docValue": "312312", "isPrim": 1, "resources": [ { "id": 23893452, "name": "national card back" }, { "id": 52524055, "name": "national card front" }, { "id": 4266737, "name": "physicalForm" } ] } ]
Now I want to get the first JSON in this array or the first element, for that I tried using
$.documents[?(@.isPrim==1)][0]
but this doesn’t work. Please help me understand how can I pick the first element here. I can use any other filter for this. My need is to pick the first element.