cfdocs
cfdocs copied to clipboard
JSON utils doesn't escape quotes or add new line characters
I went to go and fix the broken example for listMap by copying the example into https://cfdocs.org/utilities/json/
"code": "Rainbow = \"Whero, Karaka, Kowhai, Kakariki, Kikorangi, Tawatawa, Mawhero\"; \r\n externalList = \"\"; \r\n reverseRainbow = listMap( rainbow, function(v,i,l) \r\n { \r\n var newValue = \"#i#:#v.reverse()#\"; \r\n externalList = externalList.append(newValue); \r\n return newValue; \r\n }); \r\n riteDump([{rainbow=rainbow},{reverseRainbow=reverseRainbow},{externalList=externalList}]); \r\n"
}],
but the output from the json generator didn't escape the " or add the newlines \r\n
code: " Rainbow = "Whero, Karaka, Kowhai, Kakariki, Kikorangi, Tawatawa, Mawhero"; externalList = ""; reverseRainbow = listMap( rainbow, function(v,i,l) { var newValue = "#i#:#v.reverse()#"; externalList = ListAppend(externalList,newValue); return newValue; }); writeDump([{rainbow=rainbow},{reverseRainbow=reverseRainbow},{externalList=externalList}]); ",
So you had new line characters in your original code and they got stripped out?
Normally you add "real" breaks which get converted to line break characters (\r\n).
- open https://cfdocs.org/listmap
- click run
- copy the content between the cfscript tags
- open https://cfdocs.org/utilities/json/
- paste in the copied code from 3 into the code textarea
- press to json
Then I get line breaks as expected oO
No matter if I use the String or the code box...
are the quotes escaped too? @shaedrich what platform, I'm on win10 with chrome
They are.
The platform and browser shouldn't make any different because the tool works server-side.
I'm on ubuntu with chromium.
That is what I get:
"code":"Rainbow = \"Whero, Karaka, Kowhai, Kakariki, Kikorangi, Tawatawa, Mawhero\"; \r\n externalList = \"\"; \r\n reverseRainbow = listMap( rainbow, function(v,i,l) \r\n { \r\n var newValue = \"#i#:#v.reverse()#\"; \r\n externalList = externalList.append(newValue); \r\n return newValue; \r\n }); \r\nwriteDump([{rainbow=rainbow},{reverseRainbow=reverseRainbow},{externalList=externalList}]); ",