web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details
Power Automate - Building Flows
Answered

Compose/ string adding backslashes, makes JSON unusable.

Like (1) ShareShare
ReportReport
Posted on 11 Aug 2022 22:29:11 by 13

I have a flow that retrieves items (an array in JSON) from dataverse. I'm then taking values from each object in the array (apply to each) for use in a compose, then append each new "compostion" to a string variable (seperated by a comma). See below

 

2022-08-11 22_58_50-Window.png

 

This works fine and my output shown in the UI is below (in this example there are two objects, both starting with "type" : "ColumnSet") 

 

 

{
 "type": "ColumnSet",
 "columns": [
 {
 "type": "Column",
 "items": [
 {
 "type": "TextBlock",
 "horizontalAlignment": "Left",
 "text": "1.",
 "wrap": true,
 "size": "Medium"
 }
 ],
 "width": "auto",
 "padding": "None",
 "spacing": "None"
 },
 {
 "type": "Column",
 "items": [
 {
 "type": "FactSet",
 "id": "9d60e7c6-611b-c2b9-b43e-af37c0154ad6",
 "facts": [
 {
 "title": "StartDate:",
 "value": "2022-08-11"
 },
 {
 "title": "EndDate:",
 "value": "2022-08-11"
 }
 ]
 }
 ],
 "width": "stretch",
 "spacing": "Small",
 "padding": "None"
 },
 {
 "type": "Column",
 "items": [
 {
 "type": "FactSet",
 "id": "274d7b95-17ae-ff6d-fa93-27568cf0fb2c",
 "facts": [
 {
 "title": "Days:",
 "value": "1"
 }
 ]
 }
 ],
 "width": "stretch",
 "spacing": "Small",
 "padding": "None"
 }
 ],
 "padding": "None"
},{
 "type": "ColumnSet",
 "columns": [
 {
 "type": "Column",
 "items": [
 {
 "type": "TextBlock",
 "horizontalAlignment": "Left",
 "text": "1.",
 "wrap": true,
 "size": "Medium"
 }
 ],
 "width": "auto",
 "padding": "None",
 "spacing": "None"
 },
 {
 "type": "Column",
 "items": [
 {
 "type": "FactSet",
 "id": "9d60e7c6-611b-c2b9-b43e-af37c0154ad6",
 "facts": [
 {
 "title": "StartDate:",
 "value": "2022-08-09"
 },
 {
 "title": "EndDate:",
 "value": "2022-08-10"
 }
 ]
 }
 ],
 "width": "stretch",
 "spacing": "Small",
 "padding": "None"
 },
 {
 "type": "Column",
 "items": [
 {
 "type": "FactSet",
 "id": "274d7b95-17ae-ff6d-fa93-27568cf0fb2c",
 "facts": [
 {
 "title": "Days:",
 "value": "2"
 }
 ]
 }
 ],
 "width": "stretch",
 "spacing": "Small",
 "padding": "None"
 }
 ],
 "padding": "None"
}

 

 

The problem comes when trying to use this string in a later action. I've used the string in a compose along with some static json

 

2022-08-11 23_06_49-Window.png

 

but when the flow is run it returns the string with backslashes all over the place, which is not valid JSON.

 

2022-08-11 23_03_41-Window.png

 

I found that using json(mystring) fixed the issue, but it only ever returns the first item in the JSON.

I have tried wrapping the use of the string in replace() to remove the "\" and "\n" but they still appear when I run the flow.

 

I have also removed all of the carriage returns in the composes, but it still inserts \ everywhere

 

 

"{\"type\":\"ColumnSet\",\"columns\":[{\"type\":\"Column\",\"items\":[{\"type\":\"TextBlock\",\"horizontalAlignment\":\"Left\",\"text\":\"1.\",\"wrap\":true,\"size\":\"Medium\"}],\"width\":\"auto\",\"padding\":\"None\",\"spacing\":\"None\"},{\"type\":\"Column\",\"items\":[{\"type\":\"FactSet\",\"id\":\"9d60e7c6-611b-c2b9-b43e-af37c0154ad6\",\"facts\":[{\"title\":\"StartDate:\",\"value\":\"2022-08-11\"},{\"title\":\"EndDate:\",\"value\":\"2022-08-11\"}]}],\"width\":\"stretch\",\"spacing\":\"Small\",\"padding\":\"None\"},{\"type\":\"Column\",\"items\":[{\"type\":\"FactSet\",\"id\":\"274d7b95-17ae-ff6d-fa93-27568cf0fb2c\",\"facts\":[{\"title\":\"Days:\",\"value\":\"1\"}]}],\"width\":\"stretch\",\"spacing\":\"Small\",\"padding\":\"None\"}],\"padding\":\"None\"},{\"type\":\"ColumnSet\",\"columns\":[{\"type\":\"Column\",\"items\":[{\"type\":\"TextBlock\",\"horizontalAlignment\":\"Left\",\"text\":\"1.\",\"wrap\":true,\"size\":\"Medium\"}],\"width\":\"auto\",\"padding\":\"None\",\"spacing\":\"None\"},{\"type\":\"Column\",\"items\":[{\"type\":\"FactSet\",\"id\":\"9d60e7c6-611b-c2b9-b43e-af37c0154ad6\",\"facts\":[{\"title\":\"StartDate:\",\"value\":\"2022-08-09\"},{\"title\":\"EndDate:\",\"value\":\"2022-08-10\"}]}],\"width\":\"stretch\",\"spacing\":\"Small\",\"padding\":\"None\"},{\"type\":\"Column\",\"items\":[{\"type\":\"FactSet\",\"id\":\"274d7b95-17ae-ff6d-fa93-27568cf0fb2c\",\"facts\":[{\"title\":\"Days:\",\"value\":\"2\"}]}],\"width\":\"stretch\",\"spacing\":\"Small\",\"padding\":\"None\"}],\"padding\":\"None\"}"

 

 

This is infuriating me now 😫, if anyone has any ideas on how to use the string as it's presented in the front end and not the "raw" string with all the extra characters It would be much appreciated!

I have the same question (0)
  • Verified answer
    Sillymansam Profile Picture
    13 on 11 Aug 2022 at 23:17:12
    Re: Compose/ string adding backslashes, makes JSON unusable.

    Solved It!


    Essentially it looks like powerautomate was automatically adding escape backslashes to my first compose with the items from dataverse, and then when i added that composition to static json inside another compose, it was "double escaping" adding backslashes again, see below  

     

    2022-08-12 00_11_06-Window.png 

     

    instead of nesting the first composition of items inside another compose, i sandwiched it between the beginning and the end of the static JSON

     

    2022-08-12 00_14_33-Window.png

  • dblynn Profile Picture
    2 on 22 Feb 2023 at 03:00:05
    Re: Compose/ string adding backslashes, makes JSON unusable.

    For anyone else who stumbles on this:

     

    Use Parse JSON to construct the request body.  

     

    Although the output from Parse JSON looks exactly the same as from compose, using these prevents the addition of escape characters.

  • Vanda_Kosztek Profile Picture
    2 on 18 Sep 2023 at 08:28:23
    Re: Compose/ string adding backslashes, makes JSON unusable.

    Although this ticket is closed, I post a response as the above responses did not really helped in my case.

    My problem was that any backslash character failed the parse json step after the compose.  

     

    What worked for me is to add manually the escape characters in a compose step (I have also escaped the double speech marks):

    replace(replace([the string you want to edit], '\', '\\'), '"', '\"')
    

     

     

    this is in practice double escaping the special characters, but still works in my case...

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 788 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 452 Moderator

#3
developerAJ Profile Picture

developerAJ 302

Last 30 days Overall leaderboard
Loading started
Loading started
Loading complete