Re: [WebDNA] TCPconnect and Bitcoin rate

This WebDNA talk-list message is from

2017


It keeps the original formatting.
numero = 113883
interpreted = N
texte = 1483 --001a113757a07d13400560ae05f6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi all, Here is the code I use to deal with JSON. - Tom *First a function to pull a value when you know what JSON node you want:* [!] +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ FUNCTION Name: smGetJsonValue ** Description: Pull out a value from a JSONobject ** Input: jsonObject =3D (the json to be parsed) - required jsonNode =3D (the node that we the value of) - required ** usage: [smGetJsonValue jsonObject=3D[url][/url]&jsonNode=3D] [/!][function name=3DsmGetJsonValue][!] [/!][text]tReturn=3D[/text][!] [/!][text]tJsonObject=3D[/text][!] [/!][text]tJsonNode=3Dnull[/text][!] [/!][showif [url][params_string][/url]^jsonObject][text]tJsonObject=3D[jsonObject][/tex= t][/showif][!] [/!][showif [url][params_string][/url]^jsonNode][text]tJsonNode=3D[jsonNode][/text][/sh= owif][!] ### Store the jsonObject in a table ### [/!][jsonstore table=3DjsonOject][tJsonObject][/jsonstore][!] ### Search the table ### [/!][search table=3DjsonOject&ne[tJsonNode]data=3Dfind_all][founditems][!] [/!][text]tReturn=3D[interpret][[tJsonNode]][/interpret][/text][!] [/!][/founditems][/search][!] ### Return the value ### [/!][return][tReturn][/return][!] [/!][/function] *Second a Json parser, that's a bit of a hack:* [text]debug=3DF[/text]

Paste some JSON

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


[showif [action]=3Dparse-json]

Sample JSON

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


[!] ------------------------------------ ### Conversion table to strip non-breaking spaces ### [/!][table name=3DjsonClean&fields=3Dfrom,to] %C2 %A0 [/table][!] ------------------------------------ ### Conversion table to facilitate spliting into key:value pairs ### [/!][table name=3DjsonSplitConversions&fields=3Dfrom,to] | ~~~~ \" ^^^^ [/table][!] ------------------------------------ ### Convert back after spliting into key:value pairs ### [/!][table name=3DjsonSplitConversionsBack&fields=3Dfrom,to] " ~~~~ | ^^^^ " [/table][!] ------------------------------------ ### pass one - run the conversions ### [/!][text]theJson=3D[convertwords table=3DjsonSplitConversions][convertchar= s table=3DjsonClean][theJson][/convertchars][/convertwords][/text][!] ------------------------------------ ### pass two - add bar to just before each key:value pair ### [/!][text]theJson=3D[grep search=3D("[^"]*"):&replace=3D|\1=3D][theJson][/grep][/text][!] ------------------------------------ ### pass three - list out the key:value pairs and assign them to text variables ### [/!][text]count=3D0[/text][listwords words=3D[url][theJson][/url]&delimiters=3D|{}][!] [/!][text]thisVal=3D[grep search=3D(,$)&replace=3D][getchars start=3D1&trim=3Dboth][convertwords table=3DjsonSplitConversionsBack][word][/convertwords][/getchars][/grep][/t= ext][!] [/!][showif [debug]=3DT][index]. [url][thisVal][/url]
[/showif][!] [/!][hideif [url][thisVal][/url]=3D][!] [/!][text]json-[format .2d][text show=3DT]count=3D[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=3Djson-&exact=3DF][name] =3D [value]
[/listvariables] [/showif] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Digital Revolutionaries 1st Floor, Castleriver House 14-15 Parliament Street Temple Bar,Dublin 2 Ireland ---------------------------------------------- [t]: + 353 1 4403907 [e]: [w]: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D On 19 December 2017 at 08:01, Terry Nair wrote: > Kindly point out the link where I can find that JSON wonder =E2=80=A6need= it for a > project. Cannot seem to trace it =E2=80=A6my poor old eyes are not as goo= d as they > used to be =E2=80=A6=F0=9F=98=89 > > > > Cheers TDn > > > > *From:* Stuart Tremain [mailto:webdna@idfk.com.au] > *Sent:* Tuesday, December 19, 2017 08:19 AM > *To:* WebDNA Talk List > *Subject:* Re: [WebDNA] TCPconnect and Bitcoin rate > > > > OK, thanks. > > > > Tom if that was you - nice job, have been using it for a few years now :) > > > > > > Kind regards > > > > Stuart Tremain > > Pharoah Lane Software > > AUSTRALIA > > webdna@idfk.com.au > > > > > > > > > > > > On 19 Dec 2017, at 11:15, Michael Davis wrote: > > > > Stuart, > > > > I think that was Tom. He had worked one up prior to JSONStore. > > > > Mike > > > > On Dec 18, 2017, at 3:32 PM, Stuart Tremain wrote: > > > > Michael > > > > Were you the person that did the JSON parser some time ago ? > > > > > > Kind regards > > > > Stuart Tremain > > Pharoah Lane Software > > AUSTRALIA > > webdna@idfk.com.au > > > > > > > > > > > > On 19 Dec 2017, at 10:22, Michael Davis wrote: > > > > Yariv, > > > > Here's a starting point for you... > > > > Had to use [middle] to get rid of some garbage, which was strange. Other > than that, it should be pretty straight forward. > > > > > > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > > > > > > > On Dec 17, 2017, at 3:54 AM, Office wrote: > > > > For the last 20 years i never had to receive data from elsewhere till > today. > > I need to ask an API for the bitcoin rate > > i wanted to use the TCPconnect for this but the sample is dead ? : > > > > http://www.webdna.us/page.dna?numero=3D264 > > > > What i need is a piece of code to get the USD =E2=80=9Crate" out of this = thing > (this number: 19,681.9725) so i can calculate the price of the product to > be divided to this to be able to show the current price in Bitcoin at my > store > > {"USD":{"code":"USD","symbol":"$","rate":"19,681.9725","description":= "United States Dollar","rate_float":19681.9725} > > This is where it update every second (or less) > > https://api.coindesk.com/v1/bpi/currentprice.json > > > > Or any other way to get a rate into my page :-) > > > > Yours, > > > > Yariv Nachshon > > http://www.plonter.co.il > > > > > > > > > > > > > > > > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > > > > > > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > > > > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > > > > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > --001a113757a07d13400560ae05f6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi all,

Here is the code I use to deal = with JSON.

- Tom



First a function to pull a value when you know wha= t JSON node you want:

[!]
<= br>

<= div>+++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++
FUNCTION Name: smGetJsonValue
=C2=A0 ** Description: Pull out a value from a JSONobject=
=C2=A0 ** Input:=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0= jsonObject =3D (the json to be parsed) - required
=C2=A0 =C2=A0 =C2=A0 =C2=A0 jsonNode =3D (the = node that we the value of) - required
=C2=A0 ** usage:=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 [smGetJsonValue jsonObject=3D[= url]<the-json-object>[/url]&jsonNode=3D<the-json-node>]

[/!][function name=3DsmGetJsonValue][!]
[/!][text]tReturn=3D[/te= xt][!]

[/!][text]tJsonObject=3D[/text][!]
[/!][text]tJsonNode=3Dnull[= /text][!]

<= /div>
[/!][showif [url][params_string][= /url]^jsonObject][text]tJsonObject=3D[jsonObject][/text][/showif][!]=
[/!][showif [url][params_string]= [/url]^jsonNode][text]tJsonNode=3D[jsonNode][/text][/showif][!]

### =C2=A0Store the jsonObject in a table =C2=A0###

<= font face=3D"monospace, monospace">[/!][jsonstore table=3DjsonOject][tJsonO= bject][/jsonstore][!]
=
### =C2=A0Search the = table =C2=A0###

[/!][search table=3Djso= nOject&ne[tJsonNode]data=3Dfind_all][founditems][!]

[/!][text]tReturn=3D[interpret][[tJsonNode]][/interpret][/text= ][!]

=
[/!][/founditems][/search][!]

### =C2=A0Return the value =C2=A0###

[/!][return][tReturn][/return][!]
[/!][/function]




Second a = Json parser, that's a bit of a hack:

= [text]debug=3DF[/text]

<h3>Paste some JSON</h3>
<= font face=3D"monospace, monospace"><p>(some samples here <a href= =3D"ht= tp://www.jquery4u.com/json/10-example-json-files/">http://www.jquery4u.com= /json/10-example-json-files/</a>)</p>
<form action=3D"[thisurl]" met= hod=3D"post">
<input type=3D"hidden" name=3D"action" value=3D= "parse-json" />
<textarea name=3D"sample-json" style=3D"width: 50%= ; height: 200px;" placeholder=3D"paste some json"></te= xtarea><br />
<button>Parse me</button>
</form>


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

<h3>Sample JSON</h3><= /font>
<pre>[text show= =3DT]theJson=3D[sample-json][/text]</pre><br /><br />


[!]

------------------------------------
### =C2=A0Conversion table to= strip non-breaking spaces ###

[/!][tab= le name=3DjsonClean&fields=3Dfrom,to]
%C2
%A= 0
[/table][!]
=


------------------------------------
### =C2=A0Conversion table to facilitate spliting into key:= value pairs =C2=A0###
=
[/!][table name= =3DjsonSplitConversions&fields=3Dfrom,to]
|~~~~
\"^^^^
[/table]= [!]

<= div>
------------------------------------
### =C2=A0Convert back after spliting into ke= y:value pairs =C2=A0###

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


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

[/!][text]theJson=3D[convertwords table=3DjsonSpl= itConversions][convertchars table=3DjsonClean][theJson][/convertchars][/con= vertwords][/text][!]
<= br>

<= div>------------------------------------
### =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=A0pa= ss three - list out the key:value pairs and assign them to text variables = =C2=A0###

<= /div>
[/!][text]count=3D0[/text][li= stwords words=3D[url][theJson][/url]&delimiters=3D|{}][!]
<= div>
[/!][text]thisVal=3D[grep search=3D(,$)&replace=3D][= getchars start=3D1&trim=3Dboth][convertwords table=3DjsonSplitConversio= nsBack][word][/convertwords][/getchars][/grep][/text][!]
<= span class=3D"gmail-Apple-tab-span" style=3D"white-space:pre">
<= /span>[/!][showif [debug]=3DT][index]. [url][thisVal][/url]<br />[/sh= owif][!]

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

[/!][/listwords][!]


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

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

[/showif]



=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Digital Revolutionar= ies
1st Floor, Castleriver House
14-15 Parliament Street
Temple Ba= r,Dublin 2
Ireland
----------------------------------------------
= [t]: + 353 1 4403907
[e]: <mailto:tom@revolutionaries.ie>
[w]: <http://www.revolution= aries.ie/>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D

On 19 December 2017 at 08:01, Terry Nair <terrynair@prism4u.com> wrote:

Kindl= y point out the link where I can find that JSON wonder =E2=80=A6need it for= a project. Cannot seem to trace it =E2=80=A6my poor old eyes are not as go= od as they used to be =E2=80=A6=F0=9F=98=89

=C2=A0

Cheers TDn

=C2=A0=

From:<= /span> Stuart Tremain [mailto:webdna@idfk.com.au]
Sent: Tuesday, December = 19, 2017 08:19 AM
To: WebDNA Talk List <talk@webdna.us>
Subject: Re:= [WebDNA] TCPconnect and Bitcoin rate

<= div>

=C2=A0

OK, thanks.

<= u>=C2=A0

Tom if that was yo= u - nice job, have been using it for a few years now :)

=C2=A0

=C2=A0

Kind regards

<= p class=3D"MsoNormal">=C2=A0

Stuart Tremain=

Pharoah Lane Software

AUST= RALIA

=C2=A0

=C2=A0

=C2=A0

=C2=A0



On 19 Dec 2017, = at 11:15, Michael Davis <admin@network13.net> wrote:

=C2=A0

= Stuart,

=C2=A0

I think that was Tom.=C2=A0 He had work= ed one up prior to JSONStore.

=C2=A0

Mike=



On Dec 18, 2017, at 3:32 PM, Stuart Tremain <webdna@idfk.com.au> wrot= e:

=C2=A0

Michael

=C2=A0

Were you= the person that did the JSON parser some time ago ?

=C2=A0

=C2=A0

Kind regards

=C2=A0

<= span style=3D"font-size:9.0pt;font-family:"Helvetica",sans-serif"= >Stuart Tremain

<= span style=3D"font-size:9.0pt;font-family:"Helvetica",sans-serif"= >Pharoah Lane Software

AUSTRALIA

= =C2=A0

=C2=A0<= u>

=C2=A0

=C2=A0=



On 19 Dec 2017, at 10:22, Michael Davis <admin@network13.net> wrote:=

=C2=A0

Yariv,

= =C2=A0

Here's a starting po= int for you...

= =C2=A0

Had to use [middle] to g= et rid of some garbage, which was strange.=C2=A0 Other than that, it should= be pretty straight forward.

=C2=A0

=C2= =A0

--------------------------= ------------------------------- This message is sent to you because yo= u are subscribed to the mailing list talk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archive= s: = http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us<bi= tcoin_price.dna>

= =C2=A0



<= /p>

On Dec 17, 2017, at 3:54 AM, Office <yariv.n@gmail.com> wrote:<= u>

=C2=A0

For the last 20 years i never had to receive data from= elsewhere till today.

I need = to ask an API for the bitcoin rate

i wanted to use the TCPconnect for this but the sample is dead ?= :

=C2=A0<= /p>

=C2= =A0

What i need is a piece of c= ode to get the USD =E2=80=9Crate" out of this thing (this number: 19,6= 81.9725) so i can calculate the price of the product to be divided to this = to be able to show the current price in Bitcoin at my store

{"USD":{"code":"USD","=symbol":"&#36;","rate":"19,681.9725&=quot;,"description":"United States Dollar","r=ate_float":19681.9725}

This is where it update every second (or less)

=

<= u>=C2=A0

Or any other way t= o get a rate into my page :-)

=C2=A0

Yours,

=C2=A0

Yariv Nachshon

=C2=A0

=C2= =A0

=C2=A0



=C2=A0

=C2=A0



---------------------------= ------------------------------ This message is sent to you because you= are subscribed to the mailing list talk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archives= : h= ttp://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us

=C2=A0

= =C2=A0

-----------------------= ---------------------------------- This message is sent to you because= you are subscribed to the mailing list talk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us arch= ives: http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us

=C2=A0<= u>

------------------------------= --------------------------- This message is sent to you because you ar= e subscribed to the mailing list talk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archives:= ht= tp://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us=

=C2=A0

------------------------------------= --------------------- This message is sent to you because you are subscribe= d to the mailing list t= alk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archives: http://www.webd= na.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us

--------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list talk@w= ebdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archives: http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: suppo= rt@webdna.us

--------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list talk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archives: http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us --001a113757a07d13400560ae05f6-- . Associated Messages, from the most recent to the oldest:

    
  1. Re: [WebDNA] TCPconnect and Bitcoin rate (Stuart Tremain 2019)
  2. Re: [WebDNA] TCPconnect and Bitcoin rate (Michael Davis 2019)
  3. Re: [WebDNA] TCPconnect and Bitcoin rate (Stuart Tremain 2017)
  4. Re: [WebDNA] TCPconnect and Bitcoin rate (Brian Harrington 2017)
  5. Re: [WebDNA] TCPconnect and Bitcoin rate (Stuart Tremain 2017)
  6. Re: [WebDNA] TCPconnect and Bitcoin rate (Stuart Tremain 2017)
  7. Re: [WebDNA] TCPconnect and Bitcoin rate (Tom Duke 2017)
  8. RE: [WebDNA] TCPconnect and Bitcoin rate ("Terry Nair" 2017)
  9. Re: [WebDNA] TCPconnect and Bitcoin rate (Stuart Tremain 2017)
  10. Re: [WebDNA] TCPconnect and Bitcoin rate (Michael Davis 2017)
  11. Re: [WebDNA] TCPconnect and Bitcoin rate (Stuart Tremain 2017)
  12. Re: [WebDNA] TCPconnect and Bitcoin rate (Michael Davis 2017)
  13. Re: [WebDNA] TCPconnect and Bitcoin rate (Office 2017)
  14. Re: [WebDNA] TCPconnect and Bitcoin rate (Stuart Tremain 2017)
  15. [WebDNA] TCPconnect and Bitcoin rate (Yariv Nachshon 2017)
  16. Re: [WebDNA] TCPconnect and Bitcoin rate (Lawrence Banahan 2017)
  17. [WebDNA] TCPconnect and Bitcoin rate (Office 2017)
1483 --001a113757a07d13400560ae05f6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi all, Here is the code I use to deal with JSON. - Tom *First a function to pull a value when you know what JSON node you want:* [!] +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ FUNCTION Name: smGetJsonValue ** Description: Pull out a value from a JSONobject ** Input: jsonObject =3D (the json to be parsed) - required jsonNode =3D (the node that we the value of) - required ** usage: [smGetJsonValue jsonObject=3D[url][/url]&jsonNode=3D] [/!][function name=3DsmGetJsonValue][!] [/!][text]tReturn=3D[/text][!] [/!][text]tJsonObject=3D[/text][!] [/!][text]tJsonNode=3Dnull[/text][!] [/!][showif [url][params_string][/url]^jsonObject][text]tJsonObject=3D[jsonObject][/tex= t][/showif][!] [/!][showif [url][params_string][/url]^jsonNode][text]tJsonNode=3D[jsonNode][/text][/sh= owif][!] ### Store the jsonObject in a table ### [/!][jsonstore table=3DjsonOject][tJsonObject][/jsonstore][!] ### Search the table ### [/!][search table=3DjsonOject&ne[tJsonNode]data=3Dfind_all][founditems][!] [/!][text]tReturn=3D[interpret][[tJsonNode]][/interpret][/text][!] [/!][/founditems][/search][!] ### Return the value ### [/!][return][tReturn][/return][!] [/!][/function] *Second a Json parser, that's a bit of a hack:* [text]debug=3DF[/text]

Paste some JSON

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

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

Sample JSON

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


[!] ------------------------------------ ### Conversion table to strip non-breaking spaces ### [/!][table name=3DjsonClean&fields=3Dfrom,to] %C2 %A0 [/table][!] ------------------------------------ ### Conversion table to facilitate spliting into key:value pairs ### [/!][table name=3DjsonSplitConversions&fields=3Dfrom,to] | ~~~~ \" ^^^^ [/table][!] ------------------------------------ ### Convert back after spliting into key:value pairs ### [/!][table name=3DjsonSplitConversionsBack&fields=3Dfrom,to] " ~~~~ | ^^^^ " [/table][!] ------------------------------------ ### pass one - run the conversions ### [/!][text]theJson=3D[convertwords table=3DjsonSplitConversions][convertchar= s table=3DjsonClean][theJson][/convertchars][/convertwords][/text][!] ------------------------------------ ### pass two - add bar to just before each key:value pair ### [/!][text]theJson=3D[grep search=3D("[^"]*"):&replace=3D|\1=3D][theJson][/grep][/text][!] ------------------------------------ ### pass three - list out the key:value pairs and assign them to text variables ### [/!][text]count=3D0[/text][listwords words=3D[url][theJson][/url]&delimiters=3D|{}][!] [/!][text]thisVal=3D[grep search=3D(,$)&replace=3D][getchars start=3D1&trim=3Dboth][convertwords table=3DjsonSplitConversionsBack][word][/convertwords][/getchars][/grep][/t= ext][!] [/!][showif [debug]=3DT][index]. [url][thisVal][/url]
[/showif][!] [/!][hideif [url][thisVal][/url]=3D][!] [/!][text]json-[format .2d][text show=3DT]count=3D[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=3Djson-&exact=3DF][name] =3D [value]
[/listvariables] [/showif] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Digital Revolutionaries 1st Floor, Castleriver House 14-15 Parliament Street Temple Bar,Dublin 2 Ireland ---------------------------------------------- [t]: + 353 1 4403907 [e]: [w]: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D On 19 December 2017 at 08:01, Terry Nair wrote: > Kindly point out the link where I can find that JSON wonder =E2=80=A6need= it for a > project. Cannot seem to trace it =E2=80=A6my poor old eyes are not as goo= d as they > used to be =E2=80=A6=F0=9F=98=89 > > > > Cheers TDn > > > > *From:* Stuart Tremain [mailto:webdna@idfk.com.au] > *Sent:* Tuesday, December 19, 2017 08:19 AM > *To:* WebDNA Talk List > *Subject:* Re: [WebDNA] TCPconnect and Bitcoin rate > > > > OK, thanks. > > > > Tom if that was you - nice job, have been using it for a few years now :) > > > > > > Kind regards > > > > Stuart Tremain > > Pharoah Lane Software > > AUSTRALIA > > webdna@idfk.com.au > > > > > > > > > > > > On 19 Dec 2017, at 11:15, Michael Davis wrote: > > > > Stuart, > > > > I think that was Tom. He had worked one up prior to JSONStore. > > > > Mike > > > > On Dec 18, 2017, at 3:32 PM, Stuart Tremain wrote: > > > > Michael > > > > Were you the person that did the JSON parser some time ago ? > > > > > > Kind regards > > > > Stuart Tremain > > Pharoah Lane Software > > AUSTRALIA > > webdna@idfk.com.au > > > > > > > > > > > > On 19 Dec 2017, at 10:22, Michael Davis wrote: > > > > Yariv, > > > > Here's a starting point for you... > > > > Had to use [middle] to get rid of some garbage, which was strange. Other > than that, it should be pretty straight forward. > > > > > > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > > > > > > > On Dec 17, 2017, at 3:54 AM, Office wrote: > > > > For the last 20 years i never had to receive data from elsewhere till > today. > > I need to ask an API for the bitcoin rate > > i wanted to use the TCPconnect for this but the sample is dead ? : > > > > http://www.webdna.us/page.dna?numero=3D264 > > > > What i need is a piece of code to get the USD =E2=80=9Crate" out of this = thing > (this number: 19,681.9725) so i can calculate the price of the product to > be divided to this to be able to show the current price in Bitcoin at my > store > > {"USD":{"code":"USD","symbol":"$","rate":"19,681.9725","description":= "United States Dollar","rate_float":19681.9725} > > This is where it update every second (or less) > > https://api.coindesk.com/v1/bpi/currentprice.json > > > > Or any other way to get a rate into my page :-) > > > > Yours, > > > > Yariv Nachshon > > http://www.plonter.co.il > > > > > > > > > > > > > > > > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > > > > > > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > > > > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > > > > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > --------------------------------------------------------- This message is > sent to you because you are subscribed to the mailing list talk@webdna.us > To unsubscribe, E-mail to: talk-leave@webdna.us archives: > http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.u= s > --001a113757a07d13400560ae05f6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi all,

Here is the code I use to deal = with JSON.

- Tom



First a function to pull a value when you know wha= t JSON node you want:

<= br>

<= div>+++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++
FUNCTION Name: smGetJsonValue
=C2=A0 ** Description: Pull out a value from a JSONobject=
=C2=A0 ** Input:=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0= jsonObject =3D (the json to be parsed) - required
=C2=A0 =C2=A0 =C2=A0 =C2=A0 jsonNode =3D (the = node that we the value of) - required
=C2=A0 ** usage:=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 [smGetJsonValue jsonObject=3D[= url]<the-json-object>[/url]&jsonNode=3D<the-json-node>]

[/!][function name=3DsmGetJsonValue][!]
[/!][text]tReturn=3D[/te= xt][!]

[/!][text]tJsonObject=3D[/text][!]
[/!][text]tJsonNode=3Dnull[= /text][!]

<= /div>
[/!][showif [url][params_string][= /url]^jsonObject][text]tJsonObject=3D[jsonObject][/text][/showif][!]=
[/!][showif [url][params_string]= [/url]^jsonNode][text]tJsonNode=3D[jsonNode][/text][/showif][!]

### =C2=A0Store the jsonObject in a table =C2=A0###

<= font face=3D"monospace, monospace">[/!][jsonstore table=3DjsonOject][tJsonO= bject][/jsonstore][!]
=
### =C2=A0Search the = table =C2=A0###

[/!][search table=3Djso= nOject&ne[tJsonNode]data=3Dfind_all][founditems][!]

[/!][text]tReturn=3D[interpret][[tJsonNode]][/interpret][/text= ][!]

=
[/!][/founditems][/search][!]

### =C2=A0Return the value =C2=A0###

[/!][return][tReturn][/return][!]
[/!][/function]




Second a = Json parser, that's a bit of a hack:

= [text]debug=3DF[/text]

<h3>Paste some JSON</h3>
<= font face=3D"monospace, monospace"><p>(some samples here <a href= =3D"ht= tp://www.jquery4u.com/json/10-example-json-files/">http://www.jquery4u.com= /json/10-example-json-files/</a>)</p>
<form action=3D"[thisurl]" met= hod=3D"post">
<input type=3D"hidden" name=3D"action" value=3D= "parse-json" />
<textarea name=3D"sample-json" style=3D"width: 50%= ; height: 200px;" placeholder=3D"paste some json"></te= xtarea><br />
<button>Parse me</button>
</form>


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

<h3>Sample JSON</h3><= /font>
<pre>[text show= =3DT]theJson=3D[sample-json][/text]</pre><br /><br />



------------------------------------
### =C2=A0Conversion table to= strip non-breaking spaces ###

[/!][tab= le name=3DjsonClean&fields=3Dfrom,to]
%C2
%A= 0
[/table][!]
=


------------------------------------
### =C2=A0Conversion table to facilitate spliting into key:= value pairs =C2=A0###
=
[/!][table name= =3DjsonSplitConversions&fields=3Dfrom,to]
|~~~~
\"^^^^
[/table]= [!]

<= div>
------------------------------------
### =C2=A0Convert back after spliting into ke= y:value pairs =C2=A0###

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


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

[/!][text]theJson=3D[convertwords table=3DjsonSpl= itConversions][convertchars table=3DjsonClean][theJson][/convertchars][/con= vertwords][/text][!]
<= br>

<= div>------------------------------------
### =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=A0pa= ss three - list out the key:value pairs and assign them to text variables = =C2=A0###

<= /div>
[/!][text]count=3D0[/text][li= stwords words=3D[url][theJson][/url]&delimiters=3D|{}][!]
<= div>
[/!][text]thisVal=3D[grep search=3D(,$)&replace=3D][= getchars start=3D1&trim=3Dboth][convertwords table=3DjsonSplitConversio= nsBack][word][/convertwords][/getchars][/grep][/text][!]
<= span class=3D"gmail-Apple-tab-span" style=3D"white-space:pre">
<= /span>[/!][showif [debug]=3DT][index]. [url][thisVal][/url]<br />[/sh= owif][!]

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

[/!][/listwords][!]


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

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

[/showif]



=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Digital Revolutionar= ies
1st Floor, Castleriver House
14-15 Parliament Street
Temple Ba= r,Dublin 2
Ireland
----------------------------------------------
= [t]: + 353 1 4403907
[e]: <mailto:tom@revolutionaries.ie>
[w]: <http://www.revolution= aries.ie/>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D

On 19 December 2017 at 08:01, Terry Nair <terrynair@prism4u.com> wrote:

Kindl= y point out the link where I can find that JSON wonder =E2=80=A6need it for= a project. Cannot seem to trace it =E2=80=A6my poor old eyes are not as go= od as they used to be =E2=80=A6=F0=9F=98=89

=C2=A0

Cheers TDn

=C2=A0=

From:<= /span> Stuart Tremain [mailto:webdna@idfk.com.au]
Sent: Tuesday, December = 19, 2017 08:19 AM
To: WebDNA Talk List <talk@webdna.us>
Subject: Re:= [WebDNA] TCPconnect and Bitcoin rate

<= div>

=C2=A0

OK, thanks.

<= u>=C2=A0

Tom if that was yo= u - nice job, have been using it for a few years now :)

=C2=A0

=C2=A0

Kind regards

<= p class=3D"MsoNormal">=C2=A0

Stuart Tremain=

Pharoah Lane Software

AUST= RALIA

=C2=A0

=C2=A0

=C2=A0

=C2=A0



On 19 Dec 2017, = at 11:15, Michael Davis <admin@network13.net> wrote:

=C2=A0

= Stuart,

=C2=A0

I think that was Tom.=C2=A0 He had work= ed one up prior to JSONStore.

=C2=A0

Mike=



On Dec 18, 2017, at 3:32 PM, Stuart Tremain <webdna@idfk.com.au> wrot= e:

=C2=A0

Michael

=C2=A0

Were you= the person that did the JSON parser some time ago ?

=C2=A0

=C2=A0

Kind regards

=C2=A0

<= span style=3D"font-size:9.0pt;font-family:"Helvetica",sans-serif"= >Stuart Tremain

<= span style=3D"font-size:9.0pt;font-family:"Helvetica",sans-serif"= >Pharoah Lane Software

AUSTRALIA

= =C2=A0

=C2=A0<= u>

=C2=A0

=C2=A0=



On 19 Dec 2017, at 10:22, Michael Davis <admin@network13.net> wrote:=

=C2=A0

Yariv,

= =C2=A0

Here's a starting po= int for you...

= =C2=A0

Had to use [middle] to g= et rid of some garbage, which was strange.=C2=A0 Other than that, it should= be pretty straight forward.

=C2=A0

=C2= =A0

--------------------------= ------------------------------- This message is sent to you because yo= u are subscribed to the mailing list talk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archive= s: = http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us<bi= tcoin_price.dna>

= =C2=A0



<= /p>

On Dec 17, 2017, at 3:54 AM, Office <yariv.n@gmail.com> wrote:<= u>

=C2=A0

For the last 20 years i never had to receive data from= elsewhere till today.

I need = to ask an API for the bitcoin rate

i wanted to use the TCPconnect for this but the sample is dead ?= :

=C2=A0<= /p>

=C2= =A0

What i need is a piece of c= ode to get the USD =E2=80=9Crate" out of this thing (this number: 19,6= 81.9725) so i can calculate the price of the product to be divided to this = to be able to show the current price in Bitcoin at my store

{"USD":{"code":"USD","=symbol":"&#36;","rate":"19,681.9725&=quot;,"description":"United States Dollar","r=ate_float":19681.9725}

This is where it update every second (or less)

=

<= u>=C2=A0

Or any other way t= o get a rate into my page :-)

=C2=A0

Yours,

=C2=A0

Yariv Nachshon

=C2=A0

=C2= =A0

=C2=A0



=C2=A0

=C2=A0



---------------------------= ------------------------------ This message is sent to you because you= are subscribed to the mailing list talk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archives= : h= ttp://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us

=C2=A0

= =C2=A0

-----------------------= ---------------------------------- This message is sent to you because= you are subscribed to the mailing list talk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us arch= ives: http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us

=C2=A0<= u>

------------------------------= --------------------------- This message is sent to you because you ar= e subscribed to the mailing list talk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archives:= ht= tp://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us=

=C2=A0

------------------------------------= --------------------- This message is sent to you because you are subscribe= d to the mailing list t= alk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archives: http://www.webd= na.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us

--------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list talk@w= ebdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archives: http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: suppo= rt@webdna.us

--------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list talk@webdna.us To unsubscribe, E-mail to: talk-leave@webdna.us archives: http://www.webdna.us/page.dna?numero=3D55 Bug Reporting: support@webdna.us --001a113757a07d13400560ae05f6-- . 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:

searching problem (1998) Pixel Pipe & Auto Resizing of images (2002) Pacific Coast Software responsiveness (was WebMerchant - MacAuthorize) (1999) Extra equals signs with IE? (More debugging questions...) (1997) Unable to open the demo file (1998) Exclude by date - multiple (1997) WebCat2 - [format thousands] (1997) no template caching (1997) Re:redirect from the errorsMessages.db entry (1997) Hiding usernames and passwords in URL (1998) Showif Or (2000) New WebCatalog 402 (UNIX) patch available... (2001) WebCatalog on Linux (2000) Re:mail list (1998) Country & Ship-to address & other fields ? (1997) Using [Include] Context (1999) Email within tmpl ? (1997) More on the email templates (I like it) (1997) Stupid question (2003) Problems with [Search] param - Mac Plugin b15 (1997)