%3CLINGO-SUB%20id%3D%22lingo-sub-1997899%22%20slang%3D%22en-US%22%3ECalling%20REST%20API%20service%20using%20JSON%20object%20with%20fixed%20order%20of%20elements%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1997899%22%20slang%3D%22en-US%22%3E%3CP%3EWhen%20calling%20a%20REST%20API%20service%20with%20a%20JSON%20payload%20from%20Logic%20Apps%2C%20Logic%20Apps%20reorders%20JSON%20elements%20alphabetically%2C%20while%20some%20services%20expects%20the%20elements%20to%20be%20in%20a%20fixed%20order%20causing%20the%20service%20call%20to%20fail%20with%20an%20error.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20behavior%20happens%20when%20constructing%20the%20JSON%20payload%20inside%20a%20compose%20action%20or%20the%20HTTP%20action%20body%20field%3B%20after%20save%2C%20the%20elements%20are%20automatically%20reordered%20alphabetically.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20standard%20definition%20of%20a%20JSON%20object%20is%3A%3C%2FP%3E%0A%3CP%3EAn%20object%20is%20an%20unordered%20collection%20of%20zero%20or%20more%20name%2Fvalue%20pairs%2C%20where%20a%20name%20is%20a%20string%20and%20a%20value%20is%20a%20string%2C%20number%2C%20boolean%2C%20null%2C%20object%2C%20or%20array.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20Example%3A%3C%2FP%3E%0A%3CP%3EA%20service%20expects%20the%20following%20JSON%20object%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%7B%3C%2FP%3E%0A%3CP%3E%22Name%22%3A%20%22XXX%20XXXX%22%2C%3C%2FP%3E%0A%3CP%3E%22Age%22%3A%20%22XX%22%3C%2FP%3E%0A%3CP%3E%7D%3C%2FP%3E%0A%3CP%3ELogic%20Apps%20reorder%20the%20elements%20of%20the%20JSON%20object%20to%20become%20as%20follows%3A%3C%2FP%3E%0A%3CP%3E%7B%3C%2FP%3E%0A%3CP%3E%22Age%22%3A%20%22XX%22%2C%3C%2FP%3E%0A%3CP%3E%22Name%22%3A%20%22XXX%20XXXX%22%3C%2FP%3E%0A%3CP%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20workaround%20this%2C%20please%20use%20the%20following%20steps%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EUse%20Variables%20%E2%80%93%20initialize%20variable%20action%20to%20initialize%20a%20string%20variable%20setting%20the%20value%20to%20the%20JSON%20object%20string.%3C%2FLI%3E%0A%3CLI%3EUse%20the%20initialized%20variable%20as%20the%20body%20for%20the%20HTTP%20action%20calling%20the%20service.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EYour%20workflow%20should%20look%20as%20follows%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22talsaifi_0-1608628998684.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F242199i97185FF7AE884B35%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22talsaifi_0-1608628998684.png%22%20alt%3D%22talsaifi_0-1608628998684.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1997899%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JSON.png%22%20style%3D%22width%3A%20449px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F242196i76A27A3986458148%2Fimage-dimensions%2F449x178%3Fv%3D1.0%22%20width%3D%22449%22%20height%3D%22178%22%20role%3D%22button%22%20title%3D%22JSON.png%22%20alt%3D%22JSON.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ECalling%20REST%20API%20service%20using%20JSON%20object%20with%20fixed%20order%20of%20elements.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1997899%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELogic%20Apps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

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:

talsaifi_0-1608628998684.png