How Can I Preserve the Order of Objects when Sending JSON from One Workflow to Another via Webhook?

This topic was automatically generated from Slack. You can find the original thread here.

According to Pi, sending JSON from one workflow to another via webhook should preserve the order of the objects. However, the trigger HTTP receiving the POST scrambles the order of the objects in the array. Is there any way to fix this?

Can you share example data / code? Arrays are ordered, so if you truly have an array of objects, that order should be maintained.

For reference, here is the array that’s being sent by POST (picture 1), and the array being returned in the next workflow (picture 2)

image.png

image.png

Got it thanks. Yes, since objects have no order of keys within them, this is expected. This is a feature of JavaScript. There are a few ways to maintain the order of keys using a different data structure, e.g. see https://stackoverflow.com/a/5525820

Thank you!

An array of the keys in the right order should work.

You can then iterate over that array and grab the corresponding values in the object.