Thanks this should add a lot of stability to the get data package.
Logan
Sent from my T-Mobile 4G LTE Device
-------- Original message --------
From: Allin Cottrell
Date:05/14/2014 1:57 PM (GMT-06:00)
To: Gretl development
Subject: Re: [Gretl-devel] built-in curl() function
On Wed, 14 May 2014, Logan Kelly wrote:
Great! This is going to add a lot of functionality!
Here's a follow-up: I've also added a function named jsonget. It's in the
snapshots for Windows and OS X quartz. To get use it on Linux you have to
build from CVS, with the json-glib-1.0 library installed (plus its "dev"
or "devel" package, if that's separate).
This function takes two string arguments: the first should be a JSON
buffer (as acquired via the curl function), and the second is the JsonPath
to what you want. The function returns a string (with one element per line
if the thing you want is an array).
For the syntax of JSON paths, see
https://developer.gnome.org/json-glib/stable/JsonPath.html or
http://goessner.net/articles/JsonPath/
Here's a complete working example:
<hansl>
set echo off
set messages off
bundle req
req.URL = "http://api.bls.gov/publicAPI/v1/timeseries/data/"
req.header = "Content-Type: application/json"
string s
sprintf s
"{\"seriesid\":[\"APU0000701111\"],\"startyear\":\"2002\",\"endyear\":\"2012\"}"
req.postdata = s
curl(&req)
s = req.output
check = jsonget(s, "$.status")
if check != "REQUEST_SUCCEEDED"
print "Failed to get data"
quit
endif
string allval = jsonget(s, "$.Results.series[0].data[*].value")
string allyrs = jsonget(s, "$.Results.series[0].data[*].year")
string allper = jsonget(s, "$.Results.series[0].data[*].period")
string val yr per
printf "obs %s\n", jsonget(s, "$.Results..seriesID")
loop while getline(allyrs, yr) --quiet
getline(allper, per)
getline(allval, val)
printf "%s:%s %s\n", yr, per+1, val
endloop
</hansl>
Allin
_______________________________________________
Gretl-devel mailing list
Gretl-devel(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-devel