If you'd like to review the complete guide to populating a word document using SharePoint data

September 12th 2021
Back to all blogs

Double quotes in JSON can be a pain. We have several actions which expect to receive data formatted as JSON:

This isn’t specific to Encodian, and many actions within Power Automate utilise the JSON format to exchange data. Find out more about the JSON standard.

Let’s consider the following basic example using our Populate Word Document action to add data to a Microsoft word document.

There is minimal opportunity for the JSON data I have provided to the ‘Document Data‘ property to become invalid. However, let’s consider the following example where we are aiming to create a new document populated from data contained with a new SharePoint list item:

The validity of the JSON data passed to the Encodian action depends on the data coming from the SharePoint list item and, therefore, the end-user entered into SharePoint. This is where things can go wrong! Recently we’ve had lots of support tickets reporting invalid JSON values caused by speech marks within the dynamic data item. For example, considering the previous model, let’s assume the ‘PO Number‘ column contained this value: P12456

{
   "poNumber":"P123456", 
   "address":"",
   "due":"" 
}

This JSON data is valid. However, what happens if the ‘PO Number‘ column contains this value: P”12456″

The following JSON is not valid due to the speech marks contained within the ‘PO Number‘ columns value: P”12456″

So how do you ensure dynamic data (and speech marks precisely) do not corrupt JSON payloads in Power Automate?

FIX: Escape double quotes in Power Automate

We’ll use the previous example to illustrate the resolution: simply use the Power Automate replace() expression to escape any speech marks contained within the dynamic data.

Expression Reference: replace(<dynamicDataHere>,'”‘,’\”‘)

The resultant JSON is now valid.

You may find this website helpful for validating JSON.

If you’re unsure how to locate JSON data provided to actions, you need to review the INPUT value in your flow’s run history. This is further explained in this article: Power Automate Run History – Inputs and Outputs.

If you’d like to review the complete guide to populating a word document using SharePoint data, check out: Add SharePoint List Item Data to a Document

Author
Jay Goodison

Managing Director

Back to all blogs

You might also be interested in...