Set request body to pass polygon coordinates(collection run)

Hi everyone,

I’m in trouble with the setting of the “raw” body of a POST request.
I wrote the raw request body like this

{
   "Geodata":{
      "dataset":[
         {
            "geoJson":{
               "coordinates":["{{coordinates}}"],
               "type":"{{type}}",
               "properties":{
                  "prop1":"{{prop1}}",
                  "prop2":"{{prop2}}"
               }
            }
         }
      ]
   },
   "date":"{{date}}"
}

With the request I need to send from 1 to n polygons, with their own set of coordinates.
I want to send this json through collection runner

[
{
"Geodata": {
    "dataset": [
      {
        "geoJson": {
          "coordinates": [
          [
            [
              11.211549007623518,
              46.07882993476238
            ],
            [
              11.210692548633489,
              46.07882993476238
            ],
            [
              11.210692548633489,
              46.078536845535325
            ],
            [
              11.211549007623518,
              46.078536845535325
            ],
            [
              11.211549007623518,
              46.07882993476238
            ]
          ]
          ],
          "type": "Polygon",
          "properties": {
            "prop1": "null",
            "prop2": "TEST"
          }
        }
      }
    ]
  },
"date": "2024-03-27T00:00:00"
}
]

but I get this error

{"error":"BAD_REQUEST","timestamp":"2024-03-29T10:34:19.074182","message":"XXXXX` from Array value (token `JsonToken.START_ARRAY`)\n at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 2, column: 19] (through reference chain: XXXXX.","status":"BAD_REQUEST"}

While, if I send normally the json as a single POST with that json directly in the body of the request, it works.

Can someone help me with this problem? I don’t understand if the problem is the raw body, the json, the collection runner o something else. The json seems to be ok, without any error.

Thanks a lot!

Your coordinates array looks wrong.

Technically its valid JSON, but you appear to have an extra array around your coordinates.

Also, what does the body for the request look like when you run this via the collection runner.

Finally, use the console log to show you what was actually sent. Does the body look correct?

Always helpful Mike.

Sorry for the late reply.

The request body is the following

{
   "Geodata":{
      "dataset":[
         {
            "geoJson":{
               "coordinates":["{{coordinates}}"],
               "type":"{{type}}",
               "properties":{
                  "prop1":"{{prop1}}",
                  "prop2":"{{prop2}}"
               }
            }
         }
      ]
   },
   "date":"{{date}}",
}

While, with the request mentioned in my firt post, I get this in the console log

{
  "Geodata":{
     "dataset":[
        {
           "geoJson":{
              "coordinates":["{{coordinates}}"],
              "type":"{{type}}",
              "properties":{
                 "prop1":"{{prop1}}",
                 "prop2":"{{prop2}}"
              }
           }
        }
     ]
  },
  "date":"2024-03-27T00:00:00",
}

It seems like it’s unable to read the “nested” part properly.
Is it just a matter of “brakets”? Because I followed your suggestion by removing a pair or brakets in the json file, but the result is the same.

Thanks again

The JSON structure for the data file needs to be an array of objects.

Each object needs to contain all of the element for each iteration.

Based on the variables in your request body, it would need to look something like this…

[
    {
        "coordinates": [
            11.211549007623518,
            46.07882993476238
        ],
        "type": "Polygon",
        "prop1": "null",
        "prop2": "test",
        "date": "2024-03-27T00:00:00"
    },
    {
        "coordinates": [
            11.210692548633489,
            46.078536845535325
        ],
        "type": "Polygon",
        "prop1": "null",
        "prop2": "test",
        "date": "2024-03-27T00:00:00"
    },
    {
        "coordinates": [
            11.210692548633489,
            46.078536845535325
        ],
        "type": "Polygon",
        "prop1": "null",
        "prop2": "test",
        "date": "2024-03-27T00:00:00"
    }
]