In this post i will look at handling apostrophes in Power Automate.
Json in Power Automate
Table of Contents
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:
- An array
- An item in an array
- An attribute value
- Dynamics content used within the data of json.
All of this is reasonably easy to understand.
Now it is time to look at the dynamic content.
Dynamic content in json
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.
Use double quotes
Ok, I’m aware that I can use double quotes instead as shown below. But this format isn’t always accepted.

Back to apostrophes
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.’.

Escape the single quotes/apostrophes
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.’.
Time of the great escape!
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.
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.
Hi,
Please can I get some help with this. In the string being passed through my flow there is a ‘ for examples Butler’s. I have tried replace(outputs(‘Get_source_event’)?[‘body/Title’],””,’\”’) and it just is not working and constantly throughs me the error of: Invalid JSON. A comma character ‘,’ was expected in scope ‘Object’.
Is there anything I can do here? I don’t want to have to tell the user they can’t user apostrophes.
Thanks
Hi Jack,
In short you will want to escape the ‘ in the text fields where there are single quotes possible. Escaping can be done by replacing the quotes with \’ or two single quotes ”