Problem sending objetcs with Collection Run

Good morning guys,

I need some help with collection runner.
Let me explain with an example

I’m able to send this json via POST method, using the entire json text in the body section. The json is the following

{
  "key": "12345",
  "datGeo": {
    "datSGM": [
      {
        "geoJson": {
          "coordinates": [
            [
              [
                2610974.5659367307,
                4256418.13717125
              ],
              [
                2610974.5659367307,
                4256283.95221125
              ],
              [
                2611085.8132967306,
                4256282.80533125
              ],
              [
                2611093.8414567304,
                4256434.193491249
              ],
              [
                2610974.5659367307,
                4256418.13717125
              ]
            ]
          ],
          "type": "Polygon",
          "properties": {
            "value1": "1",
            "value2": "420"

          }
        }
      }
    ]
  },
  "datetime": "2020-01-01"
}

Given that I need to send tons of those kind of json, I was hoping to use collection runner but, with collection runner nothing works.

I use collection runner passing the same json written before.
The body of the POST method is this one

{
"datGeo": {
    "datSGM": [
        {
        "geoJson": {
            "coordinates": [[{{coordinates}}]],
            "type": "{{type}}",
            "properties": {
                "value1": "{{value1}}",
                "value2": "{{value2}}"
                }
            }
        }
    ]
},
"datetime": "{{datetime}}"
}

The “key” field is a variabile in the POST url.

If I upload the json file, the preview is this

As you can see, Postman is not able to deseriazile the object.
When I try to run this collection, the response is this one

{“error”:“BAD_REQUEST”,“timestamp”:“2024-03-29T10:34:19.074182”,“message”:"DatSGMDto from Array value (token JsonToken.START_ARRAY`)\n at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream);

And my request body is this (only “datetime” is present)

{
"datGeo": {
    "datSGM": [
        {
        "geoJson": {
            "coordinates": [[{{coordinates}}]],
            "type": "{{type}}",
            "properties": {
                "value1": "{{value1}}",
                "value2": "{{value2}}"
                }
            }
        }
    ]
},
  "datetime": "2020-01-01"
}

Where I’m wrong? Could someone help me please?
Thanks a lot!

The JSON format for the collection runner is an array of objects.

Each iteration will process the data from the current object.

You can’t just copy the complex JSON from a working single request and then throw it at the collection runner. Your coordinates is an array of arrays.

If you only need the coordinates, and value1/value2, then your JSON data file needs to just have these elements.

[
    {
        "coordinates": [
            [
                2611093.8414567304,
                4256434.193491249
            ],
            [
                2610974.5659367307,
                4256418.13717125
            ]
        ],
        "value1": "123",
        "value2": "456"
    },
    {
        "coordinates": [
            [
                2610974.5659367307,
                4256418.13717125
            ],
            [
                2610974.5659367307,
                4256283.95221125
            ]
        ],
        "value1": "321",
        "value2": "654"
    }
]

Thanks for your quik reply!
I tired what you suggested but I miss one point: when I send 2 polygons, the request sends only one (the last one in order as written in the json).

In the POST method I use the same Body as written in my first post, while my json is now like this:

[
{
"key": "12345",
"datetime": "2020-01-01",
          "coordinates": 
          [
          [
            "[11.11804327779592,46.0961763670706]",
            "[11.113710341898752,46.0961763670706]",
            "[11.113710341898752,46.09391779293779]",
            "[11.11804327779592,46.09391779293779]",
            "[11.11804327779592,46.0961763670706]"
          ]
        ],
          "type": "Polygon",
          "IDPolygon": 1336,
            "value1": 3,
            "value2": "A",     
          "coordinates": 
          [
          [
            "[10.11804327779592,46.0961763670706]",
            "[10.113710341898752,46.0961763670706]",
            "[10.113710341898752,46.09391779293779]",
            "[10.11804327779592,46.09391779293779]",
            "[10.11804327779592,46.0961763670706]"
          ]
        ],
          "type": "Polygon",
          "IDPolygon": 1369,
            "value1": 5,
            "value2": "B"
}
]

For sure there is another mistake, but I don’t how to solve it. Maybe it’s how I wrote the Body? Something else?

P.S. In the json we used double quotes to treat coordinates like a string, otherwise it doesn’t work at all

Ty

I can’t answer that as that will be down to the API specification.

The JSON you just posted is invalid as you have duplicate keys.

Your original post had the body as an object, where the latest post is an array.

Your coordinates and the corresponding keys\values probably need to be in separate objects which would then make them unique.

However, you really need to review the specification to ensure this is correct and that the format for the body is compliant for the API.

Please note, this just relate to the body for the request. The format for the JSON data file needs to be an array of objects. That’s the only format it will accept. Just to ensure we aren’t mixing the two elements (that are both using JSON).

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.