In this post i will look at handling apostrophes in Power Automate.
Almost all data in Power Automate is handled using json. Just like with Xml in the past, it is important to understand the limitations of json. An example of json usage in Flow is shown below.
In the above example shows:
All of this is reasonably easy to understand.
Now it is time to look at the dynamic content.
Consider the following flow.
The first action creates some text. The second action creates json text and the 3rd action converts this into a json object.
This all works and the json object can be created as shown above.
Ok, I’m aware that I can use double quotes instead as shown below. But this format isn’t always accepted.
Now imagine that the data has a single quote. I’m sure it is easy to imagine that someone leaves a comment like: I don’t like this.
This will result in errors like the one below.
InvalidTemplate. Unable to process template language expressions in action ‘Compose’ inputs at line ‘1’ and column ‘2655’: ‘The template language function ‘json’ parameter is not valid. The provided value ‘[{ ‘value’:’don’t like this’ }]’ cannot be parsed: ‘After parsing a value an unexpected character was encountered: t. Path ‘[0].value’, line 1, position 17.’. Please see https://aka.ms/logicexpressions#json for usage details.’.
With the following replace expression we can now fix this.
replace(outputs('Do_not_like_this'),'''','\''')
But what if your initial text includes a \
Now we’ve got a problem.
When you have a \ included in your text’s included in the json then you will get the following message.
InvalidTemplate. Unable to process template language expressions in action ‘Compose’ inputs at line ‘1’ and column ‘2655’: ‘The template language function ‘json’ parameter is not valid. The provided value ‘[{ ‘value’:’don\’t like this \ or maybe it is ok’ }]’ cannot be parsed: ‘Bad JSON escape sequence: \ . Path ‘[0].value’, line 1, position 32.’. Please see https://aka.ms/logicexpressions#json for usage details.’.
Earlier we already used the following expression:
replace(outputs('Do_not_like_this'),'''','\''')
Now we need to escape the \
My first idea was to use the following expression:
replace(replace(outputs('Do_not_like_this'),'\','\'),'''','\''')
But this didn’t work very well. I even tried the Parse JSON action instead of the json function but in both cases the output is now giving me \
Even though the output is in my opinion not completely right here. I expected to see: “don\’t like this \ or maybe it is ok”. When I use the json generated it is actually correct.
Last week Shane Young asked me about calculating the Sum for a SharePoint column in…
In Power Apps when you do a Patch to create a new item or to…
Getting started with adaptive cards can be difficult. In this post i have written some…
In this post I will look at how to create PDF documents from data. Use…
We all know this problem, you have a nested array in Power Automate but how…
Yesterday one of my clients showed me an issues where the Advanced settings didn't load.…
View Comments
Did you try two single quotes in a row?
Two single quotes could possibly do it to but I find it becoming very complicated to escape the escaping single quote. It becomes very confusing when you have to put 4 or 8 quotes in place.