[WebDNA] JSON Parser

This WebDNA talk-list message is from

2014


It keeps the original formatting.
numero = 111113
interpreted = N
texte = --bcaec547c7dd63823704f2de5134 Content-Type: text/plain; charset=UTF-8 Hi all, There has been talk on the list in the past about a JSON parser. I have knocked together a cheap and nasty parser which tries to assign all of the key:value pairs to WebDNA variables. You can try it here: https://www.revolutionaries.ie/admin/test-json.tmpl It doesn't properly parse the JSON but it might help someone. The code is below. - Tom [text]debug=F[/text]

Paste some JSON

(some samples here http://www.jquery4u.com/json/10-example-json-files/)


[showif [action]=parse-json]

Sample JSON

[text show=T]theJson=[sample-json][/text]


[!] ------------------------------------ ### Conversion table to strip non-breaking spaces ### [/!][table name=jsonClean&fields=from,to] %C2 %A0 [/table][!] ------------------------------------ ### Conversion table to facilitate spliting into key:value pairs ### [/!][table name=jsonSplitConversions&fields=from,to] | ~~~~ \" ^^^^ [/table][!] ------------------------------------ ### Convert back after spliting into key:value pairs ### [/!][table name=jsonSplitConversionsBack&fields=from,to] " ~~~~ | ^^^^ " [/table][!] ------------------------------------ ### pass one - run the conversions ### [/!][text]theJson=[convertwords table=jsonSplitConversions][convertchars table=jsonClean][theJson][/convertchars][/convertwords][/text][!] ------------------------------------ ### pass two - add bar to just before each key:value pair ### [/!][text]theJson=[grep search=("[^"]*"):&replace=|\1=][theJson][/grep][/text][!] ------------------------------------ ### pass three - list out the key:value pairs and assign them to text variables ### [/!][text]count=0[/text][listwords words=[url][theJson][/url]&delimiters=|{}][!] [/!][text]thisVal=[grep search=(,$)&replace=][getchars start=1&trim=both][convertwords table=jsonSplitConversionsBack][word][/convertwords][/getchars][/grep][/text][!] [/!][showif [debug]=T][index]. [url][thisVal][/url]
[/showif][!] [/!][hideif [url][thisVal][/url]=][!] [/!][text]json-[format .2d][text show=T]count=[math][count]+1[/math][/text][/format]-[thisVal][/text][!] [/!][/hideif][!] [/!][/listwords][!] ------------------------------------ ### Let's have a look at the variables ### [/!]

JSON Assigned to Text Variables

[listvariables name=json-&exact=F][name] = [value]
[/listvariables] [/showif] --bcaec547c7dd63823704f2de5134 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi all,

There has been talk on the list= in the past about a JSON parser. =C2=A0I have knocked together a cheap and= nasty parser which tries to assign all of the key:value pairs to WebDNA va= riables. =C2=A0 You can try it here:

=C2=A0 =C2=A0=C2=A0https://www.revolutionaries.ie/admin/test= -json.tmpl

It doesn't properly parse the J= SON but it might help someone. =C2=A0 The code is below.

- Tom




[text]debug=3DF[/text]

&= lt;h3>Paste some JSON</h3>
<p>(some samples here &= lt;a href=3D"http://www.jquery4u.com/json/10-example-json-files/">http://www.jqu= ery4u.com/json/10-example-json-files/</a>)</p>
<form action=3D"[thisurl]" method=3D"post"><= /div>
<input type=3D"hidden" name=3D"action" val= ue=3D"parse-json" />
<textarea name=3D"sampl= e-json" style=3D"width: 50%; height: 200px;" placeholder=3D&= quot;paste some json"></textarea><br />
<button>Parse me</button>
</form>


[showif [action]=3Dparse-json]
<h3>Sample JSON</h3>
<pre>[text sh= ow=3DT]theJson=3D[sample-json][/text]</pre><br /><br />


[!]


<= div>--------------------= ----------------
### =C2=A0Conversion table to strip non-breaking spaces ###

[/!][table name=3DjsonClean&fields=3Dfrom,to]
=
%C2
%A0
[/table][!]


------------------------------------
### =C2=A0Conversion table to facilitate spliting = into key:value pairs =C2=A0###

[/!][table name=3DjsonSplitConversions&fields=3Dfro= m,to]
|~~~~
\"^^^^
[/table][!]


------------------------------------
### =C2=A0Convert back after spliting int= o key:value pairs =C2=A0###

[/!][table name=3DjsonSplitConversionsBack&fields= =3Dfrom,to]
"
~~~~|
^^^^"
[/table][!]


------------------------------------
=
### =C2=A0pass one = - run the conversions =C2=A0###

[/!][text]theJson=3D[convertwords table=3DjsonSplitConv= ersions][convertchars table=3DjsonClean][theJson][/convertchars][/convertwo= rds][/text][!]


------------------------------------
### =C2=A0pass two = - add bar to just before each key:value pair ###

[= /!][text]theJson=3D[grep search=3D("[^"]*"):&replace=3D|= \1=3D][theJson][/grep][/text][!]


------------------------------------
### =C2=A0pass three - list out the key:v= alue pairs and assign them to text variables =C2=A0###

[/!][text]count=3D0[/text][listwords words=3D[url][theJ= son][/url]&delimiters=3D|{}][!]

[/!][text]thisVal=3D[grep search=3D(,$= )&replace=3D][getchars start=3D1&trim=3Dboth][convertwords table=3D= jsonSplitConversionsBack][word][/convertwords][/getchars][/grep][/text][!]<= /div>

[/!][showif [debug]=3DT][index].= [url][thisVal][/url]<br />[/showif][!]

[/!][hideif [url][t= hisVal][/url]=3D][!]
= [/!][text]json-[format .2d][text show=3DT]count=3D[math][count]+1[/= math][/text][/format]-[thisVal][/text][!]
[/!][/hideif][!]

[/!][/listwords][!]


----------------= --------------------
### =C2=A0Let's= have a look at the variables =C2=A0###

[/!]<h3= >JSON Assigned to Text Variables</h3>
[listvariables nam= e=3Djson-&exact=3DF][name] =3D [value]<br />
[/listvariables]

[/showif]
--bcaec547c7dd63823704f2de5134-- Associated Messages, from the most recent to the oldest:

    
  1. Re: [WebDNA] JSON Parser (David Bastedo 2014)
  2. Re: [WebDNA] JSON Parser (Tom Duke 2014)
  3. Re: [WebDNA] JSON Parser (David Bastedo 2014)
  4. Re: [WebDNA] JSON Parser (Stuart Tremain 2014)
  5. Re: [WebDNA] JSON Parser (Donovan Brooke 2014)
  6. [WebDNA] JSON Parser (Tom Duke 2014)
--bcaec547c7dd63823704f2de5134 Content-Type: text/plain; charset=UTF-8 Hi all, There has been talk on the list in the past about a JSON parser. I have knocked together a cheap and nasty parser which tries to assign all of the key:value pairs to WebDNA variables. You can try it here: https://www.revolutionaries.ie/admin/test-json.tmpl It doesn't properly parse the JSON but it might help someone. The code is below. - Tom [text]debug=F[/text]

Paste some JSON

(some samples here http://www.jquery4u.com/json/10-example-json-files/)

[thisurl]" method="post">
[showif [action]=parse-json]

Sample JSON

[text show=T]theJson=[sample-json][/text]


[!] ------------------------------------ ### Conversion table to strip non-breaking spaces ### [/!][table name=jsonClean&fields=from,to] %C2 %A0 [/table][!] ------------------------------------ ### Conversion table to facilitate spliting into key:value pairs ### [/!][table name=jsonSplitConversions&fields=from,to] | ~~~~ \" ^^^^ [/table][!] ------------------------------------ ### Convert back after spliting into key:value pairs ### [/!][table name=jsonSplitConversionsBack&fields=from,to] " ~~~~ | ^^^^ " [/table][!] ------------------------------------ ### pass one - run the conversions ### [/!][text]theJson=[convertwords table=jsonSplitConversions][convertchars table=jsonClean][theJson][/convertchars][/convertwords][/text][!] ------------------------------------ ### pass two - add bar to just before each key:value pair ### [/!][text]theJson=[grep search=("[^"]*"):&replace=|\1=][theJson][/grep][/text][!] ------------------------------------ ### pass three - list out the key:value pairs and assign them to text variables ### [/!][text]count=0[/text][listwords words=[url][theJson][/url]&delimiters=|{}][!] [/!][text]thisVal=[grep search=(,$)&replace=][getchars start=1&trim=both][convertwords table=jsonSplitConversionsBack][word][/convertwords][/getchars][/grep][/text][!] [/!][showif [debug]=T][index]. [url][thisVal][/url]
[/showif][!] [/!][hideif [url][thisVal][/url]=][!] [/!][text]json-[format .2d][text show=T]count=[math][count]+1[/math][/text][/format]-[thisVal][/text][!] [/!][/hideif][!] [/!][/listwords][!] ------------------------------------ ### Let's have a look at the variables ### [/!]

JSON Assigned to Text Variables

[listvariables name=json-&exact=F][name] = [value]
[/listvariables] [/showif] --bcaec547c7dd63823704f2de5134 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi all,

There has been talk on the list= in the past about a JSON parser. =C2=A0I have knocked together a cheap and= nasty parser which tries to assign all of the key:value pairs to WebDNA va= riables. =C2=A0 You can try it here:


It doesn't properly parse the J= SON but it might help someone. =C2=A0 The code is below.

- Tom




[text]debug=3DF[/text]

&= lt;h3>Paste some JSON</h3>
<form action=3D"[thisurl]" method=3D"post"><= /div>
<input type=3D"hidden" name=3D"action" val= ue=3D"parse-json" />
<textarea name=3D"sampl= e-json" style=3D"width: 50%; height: 200px;" placeholder=3D&= quot;paste some json"></textarea><br />
<button>Parse me</button>
</form>


[showif [action]=3Dparse-json]
<h3>Sample JSON</h3>
<pre>[text sh= ow=3DT]theJson=3D[sample-json][/text]</pre><br /><br />




<= div>--------------------= ----------------
### =C2=A0Conversion table to strip non-breaking spaces ###

[/!][table name=3DjsonClean&fields=3Dfrom,to]
=
%C2
%A0
[/table][!]


------------------------------------
### =C2=A0Conversion table to facilitate spliting = into key:value pairs =C2=A0###

[/!][table name=3DjsonSplitConversions&fields=3Dfro= m,to]
|~~~~
\"^^^^
[/table][!]


------------------------------------
### =C2=A0Convert back after spliting int= o key:value pairs =C2=A0###

[/!][table name=3DjsonSplitConversionsBack&fields= =3Dfrom,to]
"
~~~~|
^^^^"
[/table][!]


------------------------------------
=
### =C2=A0pass one = - run the conversions =C2=A0###

[/!][text]theJson=3D[convertwords table=3DjsonSplitConv= ersions][convertchars table=3DjsonClean][theJson][/convertchars][/convertwo= rds][/text][!]


------------------------------------
### =C2=A0pass two = - add bar to just before each key:value pair ###

[= /!][text]theJson=3D[grep search=3D("[^"]*"):&replace=3D|= \1=3D][theJson][/grep][/text][!]


------------------------------------
### =C2=A0pass three - list out the key:v= alue pairs and assign them to text variables =C2=A0###

[/!][text]count=3D0[/text][listwords words=3D[url][theJ= son][/url]&delimiters=3D|{}][!]

[/!][text]thisVal=3D[grep search=3D(,$= )&replace=3D][getchars start=3D1&trim=3Dboth][convertwords table=3D= jsonSplitConversionsBack][word][/convertwords][/getchars][/grep][/text][!]<= /div>

[/!][showif [debug]=3DT][index].= [url][thisVal][/url]<br />[/showif][!]

[/!][hideif [url][t= hisVal][/url]=3D][!]
= [/!][text]json-[format .2d][text show=3DT]count=3D[math][count]+1[/= math][/text][/format]-[thisVal][/text][!]
[/!][/hideif][!]

[/!][/listwords][!]


----------------= --------------------
### =C2=A0Let's= have a look at the variables =C2=A0###

[/!]<h3= >JSON Assigned to Text Variables</h3>
[listvariables nam= e=3Djson-&exact=3DF][name] =3D [value]<br />
[/listvariables]

[/showif]
--bcaec547c7dd63823704f2de5134-- 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:

default image if image in code not available (2003) [OT] Am I an Idiot? (2004) Modulo function? (2000) [sendmail] and [formvariables] (1997) OT: javascript help (2003) Three new problems, maybe a fourth (1997) Grep support request for SMSI ... (2003) [LOOKUP] (1997) I have observed and I am gone. (1998) Mac Lockup Problems (1998) How To question on setting up downloads (1997) [index] (1997) Ok here is a question? (1997) Help with Shipping Costs (1997) [SendMail] from a form? (1998) Determining Method (2000) Help with nested search (1998) Anyone with a solution for this? (2001) How to redirect based on price subtotal? (1998) Associative lookup style? + bit more (1997)