How to specify nested json body in POST request

Viewed 3452

I'm trying to set Artillery config to be able to send nested JSON body. This is how my configuration looks like:

config:
  target: <URL>
  phases:
    - duration: 10
      arrivalRate: 20
  processor: "./input-parser.js"
scenarios:
  - flow:
    - function: "parseJsonFile"
    - post:
        url: /workflow-instance
        headers:
           Content-Type: "application/json"
        json:
          name: "{{ name }}"
          namespace: "{{ namespace }}"
          template_name: "{{ template_name }}"
          attributes: "{{ attributes }}"
    - get:
        url: "/workflow-instance/status?name={{ template_name }}&namespace={{ namespace }}"

I have a problem with "attributes" because the content of attributes is:

{ pod_name: 'POD_NAME', port: 'PORT_NUMBER' }

So basically, this will not work:

attributes: "{ pod_name: 'POD_NAME', port: 'PORT_NUMBER' }"

as well as this:

attributes:
  pod_name: 'POD_NAME'
  port: 'PORT_NUMBER'

I didn't found good examples for this particular case in Artillery docs.

1 Answers

The following workaround worked for me Embedding JSON Data into YAML file

Then you'd have to change your attributes for:

attributes: '{ pod_name: "POD_NAME", port: "PORT_NUMBER" }'

I'm using:

Artillery: 1.7.9
Artillery Pro: not installed (https://artillery.io/pro)
Node.js: v14.6.0
OS: darwin/x64
Related