skip to Main Content

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


  1. To extract ids where "isFolder": false, use:

    Python with jsonpath-ng:

    from jsonpath_ng.ext import parse
    
    # JSON response
    json_response = {
        "data": {
            "tileGrid": {
                "items": [
                    {"isFolder": True, "id": "123456"},
                    {"isFolder": False, "id": "6789192"}
                ]
            }
        }
    }
    
    jsonpath_expr = parse("$.data.tileGrid.items[?(@.isFolder == false)].id")
    ids = [match.value for match in jsonpath_expr.find(json_response)]
    print(ids)  # Output: ['6789192']
    

    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.

    Login or Signup to reply.
  2. The $..[?(@.isFolder == false)].id expression is correct

    enter image description here

    Make sure that the response you’re getting is valid JSON

    More information: JMeter’s JSON Path Extractor Plugin – Advanced Usage Scenarios

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search