I have a response with nested array and I need to extract id’s for objects which have attribute "isFolder" = false. How can I do that?
I’ve tried using JSON extractor with pattern
$.data.tileGrid.items[?(@.isFolder == false)][1].id
also tried get an array and then just pickup a random value with a 0-match
$..[?(@.isFolder == false)].id
but didnt work – debug sampler shows an empty variable. response looks like
{
"data": {
"navigation": {
"hasNextPage": true,
"urlNextPage": "/docs/shared/?nav-folder_list_14=page-2",
"pageSize": 50,
"currentPage": 1
},
"tileGrid": {
"itemType": "BX.Disk.TileGrid.Item",
"id": "folder_list_14",
"items": [
{
"isFile": false,
"canAdd": true,
"link": "/docs/shared/path/%D0%9F%D0%9A%D0%9E/",
"isFolder": true,
"id": "6789192",
"isSymlink": false
},
...
{
"isFile": true,
"canAdd": true,
"link": "/docs/shared/path/%D0%9F%D0%9A%D0%9E/",
"isFolder": false,
"id": "6789192",
"isSymlink": false
}
]
}
}
}
2
Answers
To extract ids where "isFolder": false, use:
Python with jsonpath-ng:
JMeter JSON Extractor:
JSONPath: $.data.tileGrid.items[?(@.isFolder == false)].id
Match No.: -1 (for all matches)
Variable: nonFolderIds
This will extract 6789192. Debug to confirm variable values.
Make sure to test pass valid JSON. use any available tools to validate JSON data.
The
$..[?(@.isFolder == false)].id
expression is correctMake sure that the response you’re getting is valid JSON
More information: JMeter’s JSON Path Extractor Plugin – Advanced Usage Scenarios