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 --f403045ea282d141d705424eb352 Content-Type: text/plain; charset=UTF-8 Hi all, Re-visting this as I am doing a lot of work involving JSON and Javascript and escaping strings was doing my head in. These functions work and only require one [convertchars] pass. Thanks to the write up by Brian and Terry here - http://www.webdna.us/page.dna?numero=183 - which outlined that both the from, 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 As Quote " %22 " BackSlash \ %5C \ ForwardSlash / / / Form Feed %08 %08 Line Feed %0A %0B Carriage Return %0D %0B Horizontal 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][convertchars table=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 As Quote " %22 " Apostraphe ' %27 ' BackSlash \ %5C \ ForwardSlash / / / Form Feed %08 %08 Line Feed %0A %0B Carriage Return %0D %0B Horizontal 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][convertchars table=tabJSESCAPE][params_string][/convertchars][/return][!] [/!][/function] [text]test_string=L "John" & \ / Joanna ' + Jane[/text] [js_escape [test_string]] Result: L \"John\" & \\ \/ Joanna \' + Jane --f403045ea282d141d705424eb352 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi all,

Re-visting this as I am doing= a lot of work involving JSON and Javascript and escaping strings was doing= my head in.

These functions work and only require one [convertchars] pass.=C2=A0= Thanks to the write up by Brian and Terry here -=C2=A0http://www.webdna.us/page.dna?numero=3D1= 83 - which outlined that both the from, and to fields are first [unurl]= 'd when using convert chars.

=
It might help someone else.

- Tom



Ref:=C2=A0
http://stackoverflow.com/questions/983451/where-can-i-find-a-li= st-of-escape-characters-required-for-my-json-ajax-return-tyd
<= div class=3D"gmail_extra">https://en.wikipedia.org/wiki/UTF-8#Codepage_layout



=
[function na= me=3Djson_escape][!]

Note =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0Char =C2=A0 =C2=A0 Hex =C2=A0 =C2=A0 Stored in W= ebDNA As
Quote =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 " =C2=A0 =C2=A0 =C2=A0 = =C2=A0%22 =C2=A0 =C2=A0 "
BackSlash =C2=A0 =C2=A0 =C2=A0 \ =C2=A0 =C2=A0= =C2=A0 =C2=A0%5C =C2=A0 =C2=A0 \
ForwardSlash =C2=A0 =C2=A0/ =C2=A0 =C2=A0 =C2= =A0 =C2=A0/ =C2=A0 =C2=A0 =C2=A0 /
<= font face=3D"monospace, monospace">Form Feed =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0%08 =C2=A0 =C2=A0 %08
Line Feed =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0%0A =C2=A0 =C2=A0 %0B
Carriage Return =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0%0D =C2=A0 =C2=A0 %0B
Horizontal Tab =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 %09 =C2=A0 =C2=A0 %1D

%= 0B and %1D added to convert data read from a WebDNA db

[/!][table name=3DtabJSONESCAPE&fields=3Dfrom,to]
%22\%22
%5C<= span class=3D"gmail-Apple-tab-span" style=3D"white-space:pre">\%5C<= /font>
= /\/<= /font>
= %08\= b
%0C\f
%0A\n
%0D\r
%09= \t
%0B\n
%1D\t
[/table][!]
[/!][return][convertchars table=3DtabJSONESCAPE][para= ms_string][/convertchars][/return][!]
[/!][/function]

[text]test_strin= g=3DL "John" & \ =C2=A0/ Joanna ' + Jane[/text]

[jso= n_escape [test_string]]

Result: L \"John\" & \\ \/ Jo= anna ' + Jane



[function name= =3Djs_escape][!]

Note =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0Char =C2=A0 =C2=A0 Hex =C2=A0 =C2=A0 Stored in WebDNA = As
Q= uote =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 " =C2=A0 =C2=A0 =C2=A0 =C2=A0%= 22 =C2=A0 =C2=A0 "
Apostraphe =C2=A0 =C2=A0 =C2=A0= 9; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0%27 =C2=A0 =C2=A0=C2=A0&= #39;
BackSl= ash =C2=A0 =C2=A0 =C2=A0 \ =C2=A0 =C2=A0 =C2=A0 =C2=A0%5C =C2=A0 =C2=A0 \
<= span class=3D"gmail-Apple-tab-span" style=3D"white-space:pre">Forwa= rdSlash =C2=A0 =C2=A0/ =C2=A0 =C2=A0 =C2=A0 =C2=A0/ =C2=A0 =C2=A0 =C2=A0 /<= /font>
= Form= Feed =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0%08 =C2=A0 =C2= =A0 %08
Line Feed =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0%0A = =C2=A0 =C2=A0 %0B
Carriage Return =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0%0D =C2=A0 = =C2=A0 %0B
= Horizontal Tab =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 %09 =C2=A0 =C2=A0 = %1D

%0B a= nd %1D added to convert data read from a WebDNA db

[/!][table name=3DtabJSESCAPE&fields=3Dfrom,to]
=
%22\%22
%27\%27
%5C<= span class=3D"gmail-Apple-tab-span" style=3D"white-space:pre">\%5C<= /font>
= /\/<= /font>
= %08\= b
%0C\f
%0A\n
%0D\r
%09= \t
%0B\n
%1D\t
[/table][!]
[/!][return][convertchars table=3DtabJSESCAPE][params= _string][/convertchars][/return][!]
= [/!][/function]

[text]test_string= =3DL "John" & \ =C2=A0/ Joanna ' + Jane[/text]

[js_e= scape [test_string]]

Result: L \"John\" & \\ \/ Joanna \= ' + Jane


--------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: archives: http://mail.webdna.us/list/talk@webdna.us Bug Reporting: support@webdna.us --f403045ea282d141d705424eb352-- . Associated Messages, from the most recent to the oldest:

    
  1. Re: [WebDNA] Escaping content for JSON (Stuart Tremain 2016)
  2. Re: [WebDNA] Escaping content for JSON (Tom Duke 2016)
  3. Re: [WebDNA] Escaping content for JSON (Tom Duke 2013)
  4. Re: [WebDNA] Escaping content for JSON (Donovan Brooke 2013)
  5. [WebDNA] Escaping content for JSON (Tom Duke 2013)
818 --f403045ea282d141d705424eb352 Content-Type: text/plain; charset=UTF-8 Hi all, Re-visting this as I am doing a lot of work involving JSON and Javascript and escaping strings was doing my head in. These functions work and only require one [convertchars] pass. Thanks to the write up by Brian and Terry here - http://www.webdna.us/page.dna?numero=183 - which outlined that both the from, 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 As Quote " %22 " BackSlash \ %5C \ ForwardSlash / / / Form Feed %08 %08 Line Feed %0A %0B Carriage Return %0D %0B Horizontal 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][convertchars table=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 As Quote " %22 " Apostraphe ' %27 ' BackSlash \ %5C \ ForwardSlash / / / Form Feed %08 %08 Line Feed %0A %0B Carriage Return %0D %0B Horizontal 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][convertchars table=tabJSESCAPE][params_string][/convertchars][/return][!] [/!][/function] [text]test_string=L "John" & \ / Joanna ' + Jane[/text] [js_escape [test_string]] Result: L \"John\" & \\ \/ Joanna \' + Jane --f403045ea282d141d705424eb352 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi all,

Re-visting this as I am doing= a lot of work involving JSON and Javascript and escaping strings was doing= my head in.

These functions work and only require one [convertchars] pass.=C2=A0= Thanks to the write up by Brian and Terry here -=C2=A0http://www.webdna.us/page.dna?numero=3D1= 83 - which outlined that both the from, and to fields are first [unurl]= 'd when using convert chars.

=
It might help someone else.

- Tom



Ref:=C2=A0
http://stackoverflow.com/questions/983451/where-can-i-find-a-li= st-of-escape-characters-required-for-my-json-ajax-return-tyd
<= div class=3D"gmail_extra">https://en.wikipedia.org/wiki/UTF-8#Codepage_layout



=
[function na= me=3Djson_escape][!]

Note =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0Char =C2=A0 =C2=A0 Hex =C2=A0 =C2=A0 Stored in W= ebDNA As
Quote =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 " =C2=A0 =C2=A0 =C2=A0 = =C2=A0%22 =C2=A0 =C2=A0 "
BackSlash =C2=A0 =C2=A0 =C2=A0 \ =C2=A0 =C2=A0= =C2=A0 =C2=A0%5C =C2=A0 =C2=A0 \
ForwardSlash =C2=A0 =C2=A0/ =C2=A0 =C2=A0 =C2= =A0 =C2=A0/ =C2=A0 =C2=A0 =C2=A0 /
<= font face=3D"monospace, monospace">Form Feed =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0%08 =C2=A0 =C2=A0 %08
Line Feed =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0%0A =C2=A0 =C2=A0 %0B
Carriage Return =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0%0D =C2=A0 =C2=A0 %0B
Horizontal Tab =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 %09 =C2=A0 =C2=A0 %1D

%= 0B and %1D added to convert data read from a WebDNA db

[/!][table name=3DtabJSONESCAPE&fields=3Dfrom,to]
%22\%22
%5C<= span class=3D"gmail-Apple-tab-span" style=3D"white-space:pre">\%5C<= /font>
= /\/<= /font>
= %08\= b
%0C\f
%0A\n
%0D\r
%09= \t
%0B\n
%1D\t
[/table][!]
[/!][return][convertchars table=3DtabJSONESCAPE][para= ms_string][/convertchars][/return][!]
[/!][/function]

[text]test_strin= g=3DL "John" & \ =C2=A0/ Joanna ' + Jane[/text]

[jso= n_escape [test_string]]

Result: L \"John\" & \\ \/ Jo= anna ' + Jane



[function name= =3Djs_escape][!]

Note =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0Char =C2=A0 =C2=A0 Hex =C2=A0 =C2=A0 Stored in WebDNA = As
Q= uote =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 " =C2=A0 =C2=A0 =C2=A0 =C2=A0%= 22 =C2=A0 =C2=A0 "
Apostraphe =C2=A0 =C2=A0 =C2=A0= 9; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0%27 =C2=A0 =C2=A0=C2=A0&= #39;
BackSl= ash =C2=A0 =C2=A0 =C2=A0 \ =C2=A0 =C2=A0 =C2=A0 =C2=A0%5C =C2=A0 =C2=A0 \
<= span class=3D"gmail-Apple-tab-span" style=3D"white-space:pre">Forwa= rdSlash =C2=A0 =C2=A0/ =C2=A0 =C2=A0 =C2=A0 =C2=A0/ =C2=A0 =C2=A0 =C2=A0 /<= /font>
= Form= Feed =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0%08 =C2=A0 =C2= =A0 %08
Line Feed =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0%0A = =C2=A0 =C2=A0 %0B
Carriage Return =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0%0D =C2=A0 = =C2=A0 %0B
= Horizontal Tab =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 %09 =C2=A0 =C2=A0 = %1D

%0B a= nd %1D added to convert data read from a WebDNA db

[/!][table name=3DtabJSESCAPE&fields=3Dfrom,to]
=
%22\%22
%27\%27
%5C<= span class=3D"gmail-Apple-tab-span" style=3D"white-space:pre">\%5C<= /font>
= /\/<= /font>
= %08\= b
%0C\f
%0A\n
%0D\r
%09= \t
%0B\n
%1D\t
[/table][!]
[/!][return][convertchars table=3DtabJSESCAPE][params= _string][/convertchars][/return][!]
= [/!][/function]

[text]test_string= =3DL "John" & \ =C2=A0/ Joanna ' + Jane[/text]

[js_e= scape [test_string]]

Result: L \"John\" & \\ \/ Joanna \= ' + Jane


--------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: archives: http://mail.webdna.us/list/talk@webdna.us Bug Reporting: support@webdna.us --f403045ea282d141d705424eb352-- . Tom Duke

DOWNLOAD WEBDNA NOW!

Top Articles:

Talk List

The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...

Related Readings:

Error Messages Returned to User (1997) [WebDNA] 3-5 GB of native WebDNA db in RAM?, else MySQL w/WebDNA [SQL] tags, else skip WebDNA altogether? (2009) OT: WebDNA and LINUX (2004) Help with sorting search results sorting (1998) [WebDNA] Cookie Enabled/Disabled (2013) Searching in multiple databases from a form (1999) name of file (2002) WebDNA Solutions ... sorry! (1997) Username for Admin Group (1997) Colors (2000) Writefile doesn't work, which permissions to use? (2005) Not really WebCat (1997) WebCat2final1 crashes (1997) Hard Questions ? (1997) TRAINING videos - Prove IT. (1998) WebCat2b13MacPlugIn - [include] (1997) PSC recommends what date format yr 2000??? (1997) problems with 2 tags (1997) WebDNA Solutions ... (1997) I got caught! (2003)