Blog Post

Azure Integration Services Blog
1 MIN READ

Calling REST API service using JSON object with fixed order of elements

talsaifi's avatar
talsaifi
Icon for Microsoft rankMicrosoft
Dec 23, 2020

When calling a REST API service with a JSON payload from Logic Apps, Logic Apps reorders JSON elements alphabetically, while some services expects the elements to be in a fixed order causing the service call to fail with an error.

 

This behavior happens when constructing the JSON payload inside a compose action or the HTTP action body field; after save, the elements are automatically reordered alphabetically.

 

The standard definition of a JSON object is:

An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.

 

For Example:

A service expects the following JSON object: 

{

"Name": "XXX XXXX",

"Age": "XX"

}

Logic Apps reorder the elements of the JSON object to become as follows:

{

"Age": "XX",

"Name": "XXX XXXX"

}

 

To workaround this, please use the following steps:

  1. Use Variables – initialize variable action to initialize a string variable setting the value to the JSON object string.
  2. Use the initialized variable as the body for the HTTP action calling the service.

Your workflow should look as follows:

Updated Dec 23, 2020
Version 1.0
No CommentsBe the first to comment