0
votes

I need regular expression that can do extract JSON structure from sequence in Jmeter Regular expression extractor

[message1]

    {
        "headers": {
            "messageId": "a0923b4c-33f6-4b0c-be53-be17332d51fa"
        },
        "payload": {
            "maxIdlePeriod": 1800
        },
        "status": {
            "code": "ok",
            "errorMessages": []
        }
    }


[message2]


    {
        "headers": {
            "messageId": "46fb53f0-c3de-4270-bad5-6f504af197f9"
        },
        "payload": {
            "termsUrl": "https://termsUrl.com",
            "termsVersion": "8201"
        }
    }

I've tried the this regexp found in other stack threads {(?:[^{}]|(?R))}, but seems recursive is not supported in JAVA - Invalid expression: {(?:[^{}]|(?R))} Sequence (?R...) not recognized

Thanks in advance

1
Use JSON Path Extractor rather than regex extractor. - Wiktor Stribiżew
Hi Wiktor, it can't be used, since the response contains sequence of json messages, not a single one that JSON path extractor relies on - Nikolay Marinov
Full response and expected outcome, please - Dmitri T
Hi Dmitri, This is sample response structure that corresponds to real case, and the goal is to extract each valid JSON structure from the response into variable iteratively. the outcome should look like --- iteration 1 - variable={"headers": {"messageId": "a0923b4c-33f6-4b0c-be53-be17332d51fa" },"payload": {"maxIdlePeriod": 1800},"status": {"code": "ok","errorMessages": []}}. ----iteration 2 - variable={"headers": {"messageId": "46fb53f0-c3de-4270-bad5-6f504af197f9"},"payload": {"termsUrl": "termsUrl.com","termsVersion": "8201"}} - Nikolay Marinov

1 Answers

0
votes

So you seem to have a sequence of different JSON "documents" in a single response, right?

Well, if you're looking for the easiest way - why not embrace them with single root, then you'd have a single JSON with the list of elements, thus you'd be able to use JSON extractor postprocessor?

If you're firm in using regexp extractor - I would likely suggest to try to switch the multi-line mode first (with (?:m)), then use something like (^\{\n$.+^\}\n$) - disclaimer: not tested!, especially for the place of begin/end line anchors in multiline mode - but I hope you got the idea (also it make sense to doublecheck whether you have \n or \r\n, and, perhaps, play with central .+ to make it more specific).

Or opt for JSR223/Beanshell postprocessor and parse you response in custom manner.