Substitute function for json

Discussion created by JaredHague on Jul 29, 2015
Latest reply on Jul 30, 2015 by beverly

Ok its been a long day so my brain may be just not thinking about this logically but I just can't figure out why..

I want to replace all my " in my text with \" and any \ with \\ . So in the case where myText is aa\bb"cc i need it to be aa\\bb\"cc

so at first I tried this

Substitute ( myText ; ["\\" ; "\\\\"];[ "\"" ; "\\\"" ]  )

and the output was aa\\\bb\\\"cc" not what I was expecting.  It appears the replacement value doesn't use the escapes so after experimenting this worked.

Substitute ( myText ; [ "\"" ; "\"" ];["\\" ; "\\"] )

what I am trying to accomplish is to have myText a value that would be safe to use as a value in a JSON object so if anybody knows a cf or something that world be great.

Thanks