[/!][text]theJson=3D[convertwords table=3DjsonSplitConv=ersions][convertchars table=3DjsonClean][theJson][/convertchars][/convertwo=rds][/text][!]
[=/!][text]theJson=3D[grep search=3D("[^"]*"):&replace=3D|=\1=3D][theJson][/grep][/text][!]
[/!][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:
--bcaec547c7dd63823704f2de5134Content-Type: text/plain; charset=UTF-8Hi all,There has been talk on the list in the past about a JSON parser. I haveknocked together a cheap and nasty parser which tries to assign all of thekey:value pairs to WebDNA variables. You can try it here: https://www.revolutionaries.ie/admin/test-json.tmplIt doesn't properly parse the JSON but it might help someone. The code isbelow.- 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][convertcharstable=jsonClean][theJson][/convertchars][/convertwords][/text]
[!]------------------------------------ ### pass two - add bar to just before each key:value pair ###[/!]
[text]theJson=[grepsearch=("[^"]*"):&replace=|\1=][theJson][/grep][/text]
[!]------------------------------------### pass three - list out the key:value pairs and assign them to textvariables ###[/!]
[text]count=0[/text][listwordswords=
[url][theJson][/url]&delimiters=|{}]
[!][/!]
[text]thisVal=[grep search=(,$)&replace=][getcharsstart=1&trim=both][convertwordstable=jsonSplitConversionsBack][word][/convertwords][/getchars][/grep][/text]
[!] [/!][showif [debug]=T][index].
[url][thisVal][/url]
[/showif]
[!] [/!][hideif
[url][thisVal][/url]=]
[!][/!]
[text]json-[format .2d][textshow=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]--bcaec547c7dd63823704f2de5134Content-Type: text/html; charset=UTF-8Content-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
&=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>
<=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]
|
~~~~
\"^^^^
------------------------------------
### =C2=A0Convert back after spliting int=o key:value pairs =C2=A0###
[/!][table name=3DjsonSplitConversionsBack&fields==3Dfrom,to]
"
~~~~
|
^^^^"
------------------------------------
=
### =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|{}]
[!]