Tuesday, December 12, 2023

Build JSON object in Power Automate

We often create custom JSON objects and pass them to an action or through a web request body. For instance, let’s consider a ‘Create item’ action. If we need to build properties, we can simply configure the JSON object in the ‘item’ section, as shown in the screenshot below.


The JSON object configured above works fine as long as the values don’t have any special characters that affect the JSON object structure. However, if the title variable contains a double quote (”), the flow would fail as the JSON structure would be disturbed.

A better alternative to fix the issue mentioned above is to use the ‘Select’ action and build the JSON object as shown in the image below. This action would take care of escaping all the special characters associated with JSON. Refer to below screenshot for building JSON with select action.


To use the object constructed in ‘Select’, refer to the 0th element from the body of the ‘Select’ output, as the ‘Select’ action would always have an array.


This approach is recommended only when JSON object values may contain special characters.