Aryéh Radlé
Aryéh Radlé

Reputation: 1332

Create json from array and send it in POST request body

Consider a variable in jMeter which contains ["beep1","beep2","beep3"]

I would like to create a JSON for a POST request which looks like this:

{
    "foo": {            
        "bar": {
            "baz": [
            {
                "value": "beep1"
            },
            {
                "value": "beep2"
            },
            {
                "value": "beep3"
            }]
        }
    }
}

Upvotes: 0

Views: 1656

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

You can do it using any of JSR223 Test Elements, the relevant code would be something like:

def builder = new groovy.json.JsonBuilder()
builder {
    foo {
        bar
                {
                    baz(Eval.me(vars.get('myVar')).collect { beep ->
                        [
                                value: beep

                        ]
                    })
                }
    }
}

Demo:

JMeter Generate JSON out of String

More information:

Upvotes: 1

Related Questions