Making Key-Value JSON Objects Work Like Lists
When working with APIs, you’ll sometimes encounter responses (or requests) that don’t follow the typical array format for lists. Instead, they represent lists of items using a key-value object structure.
{ "name" : "Test", "lineitems" : { "126474" : { "id" : "126474", "lastname" : "Test1", "firstname" : "X" }, "126475" : { "id" : "126475", "lastname" : "Test2", "firstname" : "Y" }, "126476" : { "id" : "126476", "lastname" : "Test3", "firstname" : "Z" } } }
In this structure:
- The lineitems node represents the list of items related to the main object.
- Each key (126474, 126475, …) is the item’s ID.
- The value is the object containing the item details.
With Declarative Webhooks, you can now handle this pattern using the Treat as a List feature.
When editing the lineitems node:
- Open the Advanced options.
- Enable the Treat as a List toggle.
Once enabled, Declarative Webhooks will automatically transform the body before mapping. After applying Treat as a List, the JSON body above will be converted into a standard list format
{ "name" : "Test", "lineitems" : [ { "id" : "126474", "lastname" : "Test1", "firstname" : "X" }, { "id" : "126475", "lastname" : "Test2", "firstname" : "Y" }, { "id" : "126476", "lastname" : "Test3", "firstname" : "Z" } } }
This transformation allows you to work with the data as a true list, unlocking powerful functionality such as running Upsert List of Records actions on the items and seamlessly mapping dynamic objects into Salesforce records.