Re: [WebDNA] Escaping content for JSON
This WebDNA talk-list message is from 2016
It keeps the original formatting.
numero = 113230
interpreted = N
texte = 818--f403045ea282d141d705424eb352Content-Type: text/plain; charset=UTF-8Hi all,Re-visting this as I am doing a lot of work involving JSON and Javascriptand escaping strings was doing my head in.These functions work and only require one [convertchars] pass. Thanks tothe write up by Brian and Terry here -http://www.webdna.us/page.dna?numero=183 - which outlined that both thefrom, and to fields are first [unurl]'d when using convert chars.It might help someone else.- Tom*Ref: **http://stackoverflow.com/questions/983451/where-can-i-find-a-list-of-escape-characters-required-for-my-json-ajax-return-tyd
**https://en.wikipedia.org/wiki/UTF-8#Codepage_layout*[function name=json_escape][!]Note Char Hex Stored in WebDNA AsQuote " %22 "BackSlash \ %5C \ForwardSlash / / /Form Feed %08 %08Line Feed %0A %0BCarriage Return %0D %0BHorizontal Tab %09 %1D%0B and %1D added to convert data read from a WebDNA db[/!][table name=tabJSONESCAPE&fields=from,to]%22 \%22%5C \%5C/ \/%08 \b%0C \f%0A \n%0D \r%09 \t%0B \n%1D \t[/table][!][/!][return][convertcharstable=tabJSONESCAPE][params_string][/convertchars][/return][!][/!][/function][text]test_string=L "John" & \ / Joanna ' + Jane[/text][json_escape [test_string]]Result: L \"John\" & \\ \/ Joanna ' + Jane[function name=js_escape][!]Note Char Hex Stored in WebDNA AsQuote " %22 "Apostraphe ' %27 'BackSlash \ %5C \ForwardSlash / / /Form Feed %08 %08Line Feed %0A %0BCarriage Return %0D %0BHorizontal Tab %09 %1D%0B and %1D added to convert data read from a WebDNA db[/!][table name=tabJSESCAPE&fields=from,to]%22 \%22%27 \%27%5C \%5C/ \/%08 \b%0C \f%0A \n%0D \r%09 \t%0B \n%1D \t[/table][!][/!][return][convertcharstable=tabJSESCAPE][params_string][/convertchars][/return][!][/!][/function][text]test_string=L "John" & \ / Joanna ' + Jane[/text][js_escape [test_string]]Result: L \"John\" & \\ \/ Joanna \' + Jane--f403045ea282d141d705424eb352Content-Type: text/html; charset=UTF-8Content-Transfer-Encoding: quoted-printable