Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I append JSON objects in Logic Apps?

We have an incoming JSON message and would like to add some additional JSON data (JSON object with some fields) to the original message. How can I add the JSON Object "GlossDef" to the position outlined below?

{
   "glossary":{
      "title":"example glossary",
      "GlossDiv":{
         "title":"S",
         "GlossList":{
            "GlossEntry":{
               "ID":"SGML",
               "SortAs":"SGML",
               "GlossTerm":"Standard Generalized Markup Language",
               "Acronym":"SGML",
               "Abbrev":"ISO 8879:1986",
***            "GlossDef":{
***              "para":"A meta-markup language, used to create markup languages such as DocBook.",
***               "GlossSeeAlso":[
***                  "GML",
***                  "XML"
***               ]
***            },
               "GlossSee":"markup"
            }**
         }
      }
   }
}
like image 446
Jay Avatar asked Jan 17 '26 12:01

Jay


1 Answers

Take a look at the 'addProperty' method in the expressions tab. Here is a question on the powerusers platform regarding this.

https://powerusers.microsoft.com/t5/Building-Flows/How-to-add-a-new-property-to-an-object-type-variable-in-Apply-to/td-p/155685

I validated it in a test example with the following steps: enter image description here

Step 1 - This is the initial object where ever you are getting it from.
Step 2 - This is just initializing a variable with the object to add, you may have to do this in some dynamic fashion but the concept is still the same.
Step 3 - Parse the object from step one, so we can extract the sub object we want to append to.
Step 4 - Extract the sub object in this case we will choose 'GlossEntry' from the Dynamic Content list coming from the parse json.
Step 5 - Using a compose, use the expression tab and use the 'appProperty' to add 'ObjectToAdd' into 'ChildObject'. Look like this: addProperty(variables('ChildObject'), 'GlossDef', variables('ObjectToAdd'))

That should get you on the right path.

like image 129
Brian Smith Avatar answered Jan 20 '26 06:01

Brian Smith