Re: [WebDNA] JSON Parser

This WebDNA talk-list message is from

2014


It keeps the original formatting.
numero = 111227
interpreted = N
texte = --Apple-Mail-D5167EF7-F274-4F81-94C1-B671EF2964B3 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable David, Hi - have you tried the listwords without the convertchars ? Just to see where the issue is coming from. - Tom Sent from my iPhone > On 14 Mar 2014, at 15:42, David Bastedo wrote: >=20 > HI all, not sure if I am experiencing a bug, or not. >=20 > I am parsing a json output. that should be pretty simple. >=20 > Sample output to parse (instagram): >=20 > {"provider_url":"http:\/\/instagram.com\/","media_id":"661162059018947119_= 192009753","title":"Drink a little drink, smoke a little smoke #jack #coke #= church #whiskeyinthejaro #whiskey #countrymusic #outlaw","url":"http:\/\/dis= tilleryimage1.ak.instagram.com\/3e92a5949b6a11e39c1412d6a650978d_8.jpg","aut= hor_name":"mitchzorn","height":640,"width":640,"version":"1.0","author_url":= "http:\/\/instagram.com\/mitchzorn","author_id":192009753,"type":"photo","pr= ovider_name":"Instagram"} >=20 > steps: >=20 > 1. conversion table >=20 > [table name=3DcleanMeJSON&fields=3Dfrom,to] > { =20 > } =20 > " > [/table] >=20 > 2. [listwords words=3D[convertchars table=3DcleanMeJSON][theOutPut][/conve= rtchars]&Delimiters=3D,] > [index] [word]
> [/listwords] >=20 > 3. result > 1 provider_url:http::///instagram.comm/ > 2 media_id:661162059018947119_192009753 > 3 title:Drink a little drink > 4 smoke a little smoke #jack #coke #church #whiskeyinthejaro #whiskey #cou= ntrymusic #outlaw > 5 url:http::///distilleryimage1.ak.instagram.comm/3e92a5949b6a11e39c1412d6= a650978d_8.jpg > 6 author_name:mitchzorn > 7 height:640 > 8 width:640 > 9 version:1.0 > 10 author_url:http::///instagram.comm/mitchzorn > 11 author_id:192009753 > 12 type:photo > 13 provider_name:Instagram >=20 >=20 >=20 > in particular, I have no idea how extra letters are getting into the resul= ts. > Note the author link: http::///instagram.comm/mitchzorn > there is an extra "m" in "comm" > and an extra ":" and an extra "/" >=20 > i noticed this before on something but thought it was the input - now I se= e it is not. >=20 > Is there anything that I have done, that should not work? >=20 > I just compared my output to Tom's Json Parser script: >=20 > json-12-provider_name =3D Instagram > json-11-type =3D photo > json-10-author_id =3D 192009753 > json-09-author_url =3D http:\/\/instagram.com\/mitchzorn > json-08-version =3D 1.0 > json-07-width =3D 640 > json-06-height =3D 640 > json-05-author_name =3D mitchzorn > json-04-url =3D http:\/\/distilleryimage1.ak.instagram.com\/3e92a5949b6a11= e39c1412d6a650978d_8.jpg > json-03-title =3D Drink a little drink, smoke a little smoke #jack #coke #= church #whiskeyinthejaro #whiskey #countrymusic #outlaw > json-02-media_id =3D 661162059018947119_192009753 > json-01-provider_url =3D http:\/\/instagram.com\/ >=20 >=20 > it's driving me a little nuts and only just realised that webcat was respo= nsible. Is this a BUG or operator error? >=20 > thanks. >=20 > d. >=20 >=20 >=20 >> On Thu, Feb 20, 2014 at 5:49 PM, Tom Duke wrote:= >> Hi all, >>=20 >> There has been talk on the list in the past about a JSON parser. I have k= nocked together a cheap and nasty parser which tries to assign all of the ke= y:value pairs to WebDNA variables. You can try it here: >>=20 >> https://www.revolutionaries.ie/admin/test-json.tmpl >>=20 >> It doesn't properly parse the JSON but it might help someone. The code i= s below. >>=20 >> - Tom >>=20 >>=20 >>=20 >>=20 >> [text]debug=3DF[/text] >>=20 >>

Paste some JSON

>>

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

>>
>> >>
>> >>
>>=20 >>=20 >> [showif [action]=3Dparse-json] >>=20 >>

Sample JSON

>>
[text show=3DT]theJson=3D[sample-json][/text]


>>=20 >>=20 >> [!] >>=20 >>=20 >> ------------------------------------ >> ### Conversion table to strip non-breaking spaces ### >>=20 >> [/!][table name=3DjsonClean&fields=3Dfrom,to] >> %C2=09 >> %A0=09 >> [/table][!] >>=20 >>=20 >> ------------------------------------ >> ### Conversion table to facilitate spliting into key:value pairs #= ## >>=20 >> [/!][table name=3DjsonSplitConversions&fields=3Dfrom,to] >> |~~~~ >> \"^^^^ >> [/table][!] >>=20 >>=20 >> ------------------------------------ >> ### Convert back after spliting into key:value pairs ### >>=20 >> [/!][table name=3DjsonSplitConversionsBack&fields=3Dfrom,to] >> "=09 >> ~~~~| >> ^^^^" >> [/table][!] >>=20 >>=20 >> ------------------------------------ >> ### pass one - run the conversions ### >>=20 >> [/!][text]theJson=3D[convertwords table=3DjsonSplitConversions][convertch= ars table=3DjsonClean][theJson][/convertchars][/convertwords][/text][!] >>=20 >>=20 >> ------------------------------------ >> ### pass two - add bar to just before each key:value pair ### >>=20 >> [/!][text]theJson=3D[grep search=3D("[^"]*"):&replace=3D|\1=3D][theJson][= /grep][/text][!] >>=20 >>=20 >> ------------------------------------ >> ### pass three - list out the key:value pairs and assign them to t= ext variables ### >>=20 >> [/!][text]count=3D0[/text][listwords words=3D[url][theJson][/url]&delimit= ers=3D|{}][!] >>=20 >> [/!][text]thisVal=3D[grep search=3D(,$)&replace=3D][getchars start=3D= 1&trim=3Dboth][convertwords table=3DjsonSplitConversionsBack][word][/convert= words][/getchars][/grep][/text][!] >> =09 >> [/!][showif [debug]=3DT][index]. [url][thisVal][/url]
[/showif= ][!] >> =09 >> [/!][hideif [url][thisVal][/url]=3D][!] >> [/!][text]json-[format .2d][text show=3DT]count=3D[math][co= unt]+1[/math][/text][/format]-[thisVal][/text][!] >> [/!][/hideif][!] >>=20 >> [/!][/listwords][!] >>=20 >>=20 >> ------------------------------------ >> ### Let's have a look at the variables ### >>=20 >> [/!]

JSON Assigned to Text Variables

>> [listvariables name=3Djson-&exact=3DF][name] =3D [value]
>> [/listvariables] >>=20 >> [/showif] >> --------------------------------------------------------- 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 Reporti= ng: support@webdna.us >=20 >=20 >=20 > --=20 > David Bastedo > Ten Plus One Communications Inc. > http://www.10plus1.com > 416.277.4499 >=20 > --------------------------------------------------------- This message is s= ent 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 --Apple-Mail-D5167EF7-F274-4F81-94C1-B671EF2964B3 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit
David,

Hi - have you tried the listwords without the convertchars ?

Just to see where the issue is coming from.

- Tom




Sent from my iPhone

On 14 Mar 2014, at 15:42, David Bastedo <david@10plus1.com> wrote:

HI all, not sure if I am experiencing a bug, or not.

I am parsing a json output. that should be pretty simple.

Sample output to parse (instagram):

{"provider_url":"http:\/\/instagram.com\/","media_id":"661162059018947119_192009753","title":"Drink a little drink, smoke a little smoke #jack #coke #church #whiskeyinthejaro #whiskey #countrymusic #outlaw","url":"http:\/\/distilleryimage1.ak.instagram.com\/3e92a5949b6a11e39c1412d6a650978d_8.jpg","author_name":"mitchzorn","height":640,"width":640,"version":"1.0","author_url":"http:\/\/instagram.com\/mitchzorn","author_id":192009753,"type":"photo","provider_name":"Instagram"}

steps:

1. conversion table

[table name=cleanMeJSON&fields=from,to]
{   
}   
"
[/table]

2. [listwords words=[convertchars table=cleanMeJSON][theOutPut][/convertchars]&Delimiters=,]
[index] [word]<br />
 [/listwords]

3. result
1 provider_url:http::///instagram.comm/
2 media_id:661162059018947119_192009753
3 title:Drink a little drink
4 smoke a little smoke #jack #coke #church #whiskeyinthejaro #whiskey #countrymusic #outlaw
5 url:http::///distilleryimage1.ak.instagram.comm/3e92a5949b6a11e39c1412d6a650978d_8.jpg
6 author_name:mitchzorn
7 height:640
8 width:640
9 version:1.0
10 author_url:http::///instagram.comm/mitchzorn
11 author_id:192009753
12 type:photo
13 provider_name:Instagram



in particular, I have no idea how extra letters are getting into the results.
Note the author link: http::///instagram.comm/mitchzorn
there is an extra "m" in "comm"
and an extra ":" and an extra "/"

i noticed this before on something but thought it was the input - now I see it is not.

Is there anything that I have done, that should not work?

I just compared my output to Tom's Json Parser script:

json-12-provider_name = Instagram
json-11-type = photo
json-10-author_id = 192009753
json-09-author_url = http:\/\/instagram.com\/mitchzorn
json-08-version = 1.0
json-07-width = 640
json-06-height = 640
json-05-author_name = mitchzorn
json-04-url = http:\/\/distilleryimage1.ak.instagram.com\/3e92a5949b6a11e39c1412d6a650978d_8.jpg
json-03-title = Drink a little drink, smoke a little smoke #jack #coke #church #whiskeyinthejaro #whiskey #countrymusic #outlaw
json-02-media_id = 661162059018947119_192009753
json-01-provider_url = http:\/\/instagram.com\/


it's driving me a little nuts and only just realised that webcat was responsible. Is this a BUG or operator error?

thanks.

d.



On Thu, Feb 20, 2014 at 5:49 PM, Tom Duke <tom@revolutionaries.ie> wrote:
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:


It doesn't properly parse the JSON but it might help someone.   The code is below.

- Tom




[text]debug=F[/text]

<h3>Paste some JSON</h3>
<form action="[thisurl]" method="post">
<input type="hidden" name="action" value="parse-json" />
<textarea name="sample-json" style="width: 50%; height: 200px;" placeholder="paste some json"></textarea><br />
<button>Parse me</button>
</form>


[showif [action]=parse-json]

<h3>Sample JSON</h3>
<pre>[text show=T]theJson=[sample-json][/text]</pre><br /><br />


[!]


------------------------------------
###  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]<br />[/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  ###

[/!]<h3>JSON Assigned to Text Variables</h3>
[listvariables name=json-&exact=F][name] = [value]<br />
[/listvariables]

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



--
David Bastedo

Ten Plus One Communications Inc.
http://www.10plus1.com
416.277.4499

--------------------------------------------------------- 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
--Apple-Mail-D5167EF7-F274-4F81-94C1-B671EF2964B3-- 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)
--Apple-Mail-D5167EF7-F274-4F81-94C1-B671EF2964B3 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable David, Hi - have you tried the listwords without the convertchars ? Just to see where the issue is coming from. - Tom Sent from my iPhone > On 14 Mar 2014, at 15:42, David Bastedo wrote: >=20 > HI all, not sure if I am experiencing a bug, or not. >=20 > I am parsing a json output. that should be pretty simple. >=20 > Sample output to parse (instagram): >=20 > {"provider_url":"http:\/\/instagram.com\/","media_id":"661162059018947119_= 192009753","title":"Drink a little drink, smoke a little smoke #jack #coke #= church #whiskeyinthejaro #whiskey #countrymusic #outlaw","url":"http:\/\/dis= tilleryimage1.ak.instagram.com\/3e92a5949b6a11e39c1412d6a650978d_8.jpg","aut= hor_name":"mitchzorn","height":640,"width":640,"version":"1.0","author_url":= "http:\/\/instagram.com\/mitchzorn","author_id":192009753,"type":"photo","pr= ovider_name":"Instagram"} >=20 > steps: >=20 > 1. conversion table >=20 > [table name=3DcleanMeJSON&fields=3Dfrom,to] > { =20 > } =20 > " > [/table] >=20 > 2. [listwords words=3D[convertchars table=3DcleanMeJSON][theOutPut][/conve= rtchars]&Delimiters=3D,] > [index] [word]
> [/listwords] >=20 > 3. result > 1 provider_url:http::///instagram.comm/ > 2 media_id:661162059018947119_192009753 > 3 title:Drink a little drink > 4 smoke a little smoke #jack #coke #church #whiskeyinthejaro #whiskey #cou= ntrymusic #outlaw > 5 url:http::///distilleryimage1.ak.instagram.comm/3e92a5949b6a11e39c1412d6= a650978d_8.jpg > 6 author_name:mitchzorn > 7 height:640 > 8 width:640 > 9 version:1.0 > 10 author_url:http::///instagram.comm/mitchzorn > 11 author_id:192009753 > 12 type:photo > 13 provider_name:Instagram >=20 >=20 >=20 > in particular, I have no idea how extra letters are getting into the resul= ts. > Note the author link: http::///instagram.comm/mitchzorn > there is an extra "m" in "comm" > and an extra ":" and an extra "/" >=20 > i noticed this before on something but thought it was the input - now I se= e it is not. >=20 > Is there anything that I have done, that should not work? >=20 > I just compared my output to Tom's Json Parser script: >=20 > json-12-provider_name =3D Instagram > json-11-type =3D photo > json-10-author_id =3D 192009753 > json-09-author_url =3D http:\/\/instagram.com\/mitchzorn > json-08-version =3D 1.0 > json-07-width =3D 640 > json-06-height =3D 640 > json-05-author_name =3D mitchzorn > json-04-url =3D http:\/\/distilleryimage1.ak.instagram.com\/3e92a5949b6a11= e39c1412d6a650978d_8.jpg > json-03-title =3D Drink a little drink, smoke a little smoke #jack #coke #= church #whiskeyinthejaro #whiskey #countrymusic #outlaw > json-02-media_id =3D 661162059018947119_192009753 > json-01-provider_url =3D http:\/\/instagram.com\/ >=20 >=20 > it's driving me a little nuts and only just realised that webcat was respo= nsible. Is this a BUG or operator error? >=20 > thanks. >=20 > d. >=20 >=20 >=20 >> On Thu, Feb 20, 2014 at 5:49 PM, Tom Duke wrote:= >> Hi all, >>=20 >> There has been talk on the list in the past about a JSON parser. I have k= nocked together a cheap and nasty parser which tries to assign all of the ke= y:value pairs to WebDNA variables. You can try it here: >>=20 >> https://www.revolutionaries.ie/admin/test-json.tmpl >>=20 >> It doesn't properly parse the JSON but it might help someone. The code i= s below. >>=20 >> - Tom >>=20 >>=20 >>=20 >>=20 >> [text]debug=3DF[/text] >>=20 >>

Paste some JSON

>>

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

>>
[thisurl]" method=3D"post"> >> >>
>> >>
>>=20 >>=20 >> [showif [action]=3Dparse-json] >>=20 >>

Sample JSON

>>
[text show=3DT]theJson=3D[sample-json][/text]


>>=20 >>=20 >> [!] >>=20 >>=20 >> ------------------------------------ >> ### Conversion table to strip non-breaking spaces ### >>=20 >> [/!][table name=3DjsonClean&fields=3Dfrom,to] >> %C2=09 >> %A0=09 >> [/table][!] >>=20 >>=20 >> ------------------------------------ >> ### Conversion table to facilitate spliting into key:value pairs #= ## >>=20 >> [/!][table name=3DjsonSplitConversions&fields=3Dfrom,to] >> |~~~~ >> \"^^^^ >> [/table][!] >>=20 >>=20 >> ------------------------------------ >> ### Convert back after spliting into key:value pairs ### >>=20 >> [/!][table name=3DjsonSplitConversionsBack&fields=3Dfrom,to] >> "=09 >> ~~~~| >> ^^^^" >> [/table][!] >>=20 >>=20 >> ------------------------------------ >> ### pass one - run the conversions ### >>=20 >> [/!][text]theJson=3D[convertwords table=3DjsonSplitConversions][convertch= ars table=3DjsonClean][theJson][/convertchars][/convertwords][/text][!] >>=20 >>=20 >> ------------------------------------ >> ### pass two - add bar to just before each key:value pair ### >>=20 >> [/!][text]theJson=3D[grep search=3D("[^"]*"):&replace=3D|\1=3D][theJson][= /grep][/text][!] >>=20 >>=20 >> ------------------------------------ >> ### pass three - list out the key:value pairs and assign them to t= ext variables ### >>=20 >> [/!][text]count=3D0[/text][listwords words=3D[url][theJson][/url]&delimit= ers=3D|{}][!] >>=20 >> [/!][text]thisVal=3D[grep search=3D(,$)&replace=3D][getchars start=3D= 1&trim=3Dboth][convertwords table=3DjsonSplitConversionsBack][word][/convert= words][/getchars][/grep][/text][!] >> =09 >> [/!][showif [debug]=3DT][index]. [url][thisVal][/url]
[/showif= ][!] >> =09 >> [/!][hideif [url][thisVal][/url]=3D][!] >> [/!][text]json-[format .2d][text show=3DT]count=3D[math][co= unt]+1[/math][/text][/format]-[thisVal][/text][!] >> [/!][/hideif][!] >>=20 >> [/!][/listwords][!] >>=20 >>=20 >> ------------------------------------ >> ### Let's have a look at the variables ### >>=20 >> [/!]

JSON Assigned to Text Variables

>> [listvariables name=3Djson-&exact=3DF][name] =3D [value]
>> [/listvariables] >>=20 >> [/showif] >> --------------------------------------------------------- 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 Reporti= ng: support@webdna.us >=20 >=20 >=20 > --=20 > David Bastedo > Ten Plus One Communications Inc. > http://www.10plus1.com > 416.277.4499 >=20 > --------------------------------------------------------- This message is s= ent 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 --Apple-Mail-D5167EF7-F274-4F81-94C1-B671EF2964B3 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit
David,

Hi - have you tried the listwords without the convertchars ?

Just to see where the issue is coming from.

- Tom




Sent from my iPhone

On 14 Mar 2014, at 15:42, David Bastedo <david@10plus1.com> wrote:

HI all, not sure if I am experiencing a bug, or not.

I am parsing a json output. that should be pretty simple.

Sample output to parse (instagram):

{"provider_url":"http:\/\/instagram.com\/","media_id":"661162059018947119_192009753","title":"Drink a little drink, smoke a little smoke #jack #coke #church #whiskeyinthejaro #whiskey #countrymusic #outlaw","url":"http:\/\/distilleryimage1.ak.instagram.com\/3e92a5949b6a11e39c1412d6a650978d_8.jpg","author_name":"mitchzorn","height":640,"width":640,"version":"1.0","author_url":"http:\/\/instagram.com\/mitchzorn","author_id":192009753,"type":"photo","provider_name":"Instagram"}

steps:

1. conversion table

[table name=cleanMeJSON&fields=from,to]
{   
}   
"
[/table]

2. [listwords words=[convertchars table=cleanMeJSON][theOutPut][/convertchars]&Delimiters=,]
[index] [word]<br />
 [/listwords]

3. result
1 provider_url:http::///instagram.comm/
2 media_id:661162059018947119_192009753
3 title:Drink a little drink
4 smoke a little smoke #jack #coke #church #whiskeyinthejaro #whiskey #countrymusic #outlaw
5 url:http::///distilleryimage1.ak.instagram.comm/3e92a5949b6a11e39c1412d6a650978d_8.jpg
6 author_name:mitchzorn
7 height:640
8 width:640
9 version:1.0
10 author_url:http::///instagram.comm/mitchzorn
11 author_id:192009753
12 type:photo
13 provider_name:Instagram



in particular, I have no idea how extra letters are getting into the results.
Note the author link: http::///instagram.comm/mitchzorn
there is an extra "m" in "comm"
and an extra ":" and an extra "/"

i noticed this before on something but thought it was the input - now I see it is not.

Is there anything that I have done, that should not work?

I just compared my output to Tom's Json Parser script:

json-12-provider_name = Instagram
json-11-type = photo
json-10-author_id = 192009753
json-09-author_url = http:\/\/instagram.com\/mitchzorn
json-08-version = 1.0
json-07-width = 640
json-06-height = 640
json-05-author_name = mitchzorn
json-04-url = http:\/\/distilleryimage1.ak.instagram.com\/3e92a5949b6a11e39c1412d6a650978d_8.jpg
json-03-title = Drink a little drink, smoke a little smoke #jack #coke #church #whiskeyinthejaro #whiskey #countrymusic #outlaw
json-02-media_id = 661162059018947119_192009753
json-01-provider_url = http:\/\/instagram.com\/


it's driving me a little nuts and only just realised that webcat was responsible. Is this a BUG or operator error?

thanks.

d.



On Thu, Feb 20, 2014 at 5:49 PM, Tom Duke <tom@revolutionaries.ie> wrote:
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:


It doesn't properly parse the JSON but it might help someone.   The code is below.

- Tom




[text]debug=F[/text]

<h3>Paste some JSON</h3>
<form action="[thisurl]" method="post">
<input type="hidden" name="action" value="parse-json" />
<textarea name="sample-json" style="width: 50%; height: 200px;" placeholder="paste some json"></textarea><br />
<button>Parse me</button>
</form>


[showif [action]=parse-json]

<h3>Sample JSON</h3>
<pre>[text show=T]theJson=[sample-json][/text]</pre><br /><br />




------------------------------------
###  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]<br />[/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  ###

[/!]<h3>JSON Assigned to Text Variables</h3>
[listvariables name=json-&exact=F][name] = [value]<br />
[/listvariables]

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



--
David Bastedo

Ten Plus One Communications Inc.
http://www.10plus1.com
416.277.4499

--------------------------------------------------------- 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
--Apple-Mail-D5167EF7-F274-4F81-94C1-B671EF2964B3-- 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:

is sku a REQUIRED field on NT (1997) unable to launch acgi in WebCat (1997) flushing databases (2003) carriage returns in data (1997) WC2.0 Memory Requirements (1997) WebCat2b15MacPlugin - [protect] (1997) multiple product databases (1997) [ot] table gap help?!? (2001) [tcp connect] (1998) Formating found categories (1997) foriegn characters and webcatalog (1997) Re:2nd WebCatalog2 Feature Request (1996) Multiple Replaces (1997) Um. silly question perhaps...but I don't know, so I'm askin'.. (2001) WebCat2 - [format thousands] (1997) Pixo support? (1998) WebDNA 4.5.1 on OSx 10.4 (2005) Question (1997) Ranking customers (2003) Searching multiple Databases (1997)