Search code examples
jsonjmeterjson-extract

Need to extract value from the JSON Response which is not start from curly braces


I have below JSON response from the request. I'm aware how to extract value from the response using JSON Extractor but here I have different json response without stating curly braces and it start from string OK. I tried wildcard operator but didn't get any result. I want to extract value 14869 from this response.

OK
[
    [
        [
            14869,
            8708,
            5032,
            463863,
            "AssignmentCardLearning",
            "{\"type\": \"AssignmentCardRefreshDone\", \"value\": {\"byEducator\": true}}",
            "{\"openTime\": 1701326839556, \"finishTime\": 1701326994605, \"postponeData\": null, \"lastTimeOpened\": 1702469689831, \"lastTimeOpenedBy\": {\"type\": \"AssignmentCardOpenedByUser\", \"value\": {}}, \"availabilityDatesM\": null, \"previousFinishTime\": null}",
            "{\"tags\": [{\"type\": \"AssignmentCardGracePeriodNotified\", \"value\": {\"closed\": false}}], \"loIds\": [], \"language\": null, \"practiceSetLOs\": [], \"packageTopicsIds\": [5032]}",
            0,
            "2023-11-30 06:47:14",
            0,
            0,
            0
        ]
    ]
]

Solution

  • JSON can begin with [ as well in case of JSON Array

    In particular your case you can do it in 2 steps:

    1. Remove this line containing OK by adding a JSR223 PostProcessor and using the following Groovy code in it:

      prev.setResponseData(prev.getResponseDataAsString().substring(prev.getResponseDataAsString().indexOf('[')),'UTF-8')
      
    2. Once done you should be able to use JSON Extractor and the following JSONPath query:

      $[0][0][0]
      

    Demo:

    enter image description here