cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ramonahyde
Frequent Visitor

Escaped double quotes and Parse JSON

Hello.

 

I've got an issue. I have some JSON object I want to convert into Power Automate object with Parse JSON. In this object, some values have escaped double quotes like this: 

 

\"

 

They are well retrieved in the Parse JSON output, but when I'm using a property in an action, the backslashes are removed.

For example, let's say that I have some Parse JSON action called parseJson with inside one property:

 

{
    "foo": "bar\""
}

 

When I'm sending a HTTP request (in my case the SharePoint API) using a property value like that:

 

{
    "foo": "@{body('parseJson')?['foo']}"
}

 

I'm obtaining this:

 

{
    "foo": "bar""
}

 

Instead of this:

 

{
    "foo": "bar\""
}

 

It ruins my request body. 😔

 

I made some test snippet (with Compose instead of HTTP request) to compare with a simple variable containing the same value. Here are some screenshots:

 

parseJson1.PNG

My Compose action is just there to show the output of

 

@{body('testJson')?['foo']}@{variables('test')}

 

parseJson2.PNG

As you can see, the backslash is still here for the variable but not for the property value.

 

As a workaround, I'm using the replace formula in the HTTP request body like this:

 

replace(body('parseJson')?['foo'], '"', '\"')

 

But it's not really practical if I have to repeat this for a large number of values. Is there any better solutions?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @ramonahyde 

 

Ah, ok, my bad.  You unusually want to keep the slash.  In that case, you need to escape both it and the quote.  The escape char is a slash also, so \" would need to be \\\".

 

DamoBird365_0-1622620987870.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

 

View solution in original post

4 REPLIES 4
DamoBird365
Super User
Super User

Hi @ramonahyde 

 

Have you tried the json() expression.  I have seen problems retrieving data from Ms Forms with escaped characters and done an article on this here https://www.damobird365.com/easily-address-escaped-characters-in-forms-response/

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

Hello,

 

 Thank you for your reply. I don't see what you mean by using json() expression. I read your blog article, if I understand it well, it cleans all the undesirable double quotes?

In my case, I just want my backslash used for escaping an double quote inside a value to not be removed in the result.

I did a test using a Compose action with json() expression and the backslash is here but it is removed when I'm displaying the value. 😥

 

 

 

Hi @ramonahyde 

 

Ah, ok, my bad.  You unusually want to keep the slash.  In that case, you need to escape both it and the quote.  The escape char is a slash also, so \" would need to be \\\".

 

DamoBird365_0-1622620987870.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

 

View solution in original post

This did the trick! Thanks a lot!! 😊

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,515)