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

Comma (") is replaced in JSON from backslash+Comma (\")

Hope you are keeping safe and healthy.

I am creating this flow where i need to post JSON body to and external API using HTTP connector. Below is the part of JSON body where i have problem and looks like.

 

 

 

"groups": ["group1@rmail.com","group2@rmail.com","group3@rmail.com","group4@rmail.com"]

 

 

 

The email addresses are coming from a multi-line text column from sharepoint list in comma separated format something like "group1@rmail.com","group2@rmail.com","group3@rmail.com","group4@rmail.com"

Problem is that the comma (") is getting converted to (\") when passed to the JSON body. something like below.

 

 

 "\"group1@rmail.com\",\"group2@rmail.com\",\"group3@rmail.com\", \"group4@rmail.com\""

 

 


I tried using the expression below but no help.

 

 

replace(triggerOutputs()?['body/DistributionLists'],'\"','"')

 

 


here is an screenshot of how the (") is replaced with (\")

 

amanverma_0-1618829936557.png

can you please advise what could be the possible fix for this?

 

Thank you!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

It's because the value you are working with is a string, not a JSON array. Although I suspect it was a JSON array to start with. But working with a string like you have, you could do something like this to turn it back into a JSON array:

2021-04-19_12-27-26.png

the expression in the compose 2 is:

split(replace(outputs('Compose'), '"', ''), ',')

Then the output comes out as:

[
  "group1@rmail.com",
  "group2@rmail.com",
  "group3@rmail.com",
  "group4@rmail.com"
]

Which is a proper JSON array. The other possibility is that you are passing your value within quotes, which means everything inside needs to be escaped.

View solution in original post

3 REPLIES 3
Paulie78
Super User
Super User

It's because the value you are working with is a string, not a JSON array. Although I suspect it was a JSON array to start with. But working with a string like you have, you could do something like this to turn it back into a JSON array:

2021-04-19_12-27-26.png

the expression in the compose 2 is:

split(replace(outputs('Compose'), '"', ''), ',')

Then the output comes out as:

[
  "group1@rmail.com",
  "group2@rmail.com",
  "group3@rmail.com",
  "group4@rmail.com"
]

Which is a proper JSON array. The other possibility is that you are passing your value within quotes, which means everything inside needs to be escaped.

View solution in original post

@Paulie78  thanks for a quick response.

That's what i was missing, worked perfectly.

Can you please elaborate what is the expression below doing?

split(replace(outputs('Compose'), '"', ''), ',')

 
Thank you very much

From the inside out...

Replace is removing the double quotes and replacing them with nothing. So at that point the string would look like:

group1@rmail.com,group2@rmail.com,group3@rmail.com,group4@rmail.com

split, then splits the string on a comma, the output of the split operation is a JSON array.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,582)