On Sun, 12 Aug 2018, Allin Cottrell wrote:
Meanwhile I can perhaps suggest a JSON-based approach to the BCB API
if I think about for a little.
Well, I see how it can be done, but I'm not sure it's an improvement
over the CSV approach.
<hansl>
BCB = "https://api.bcb.gov.br/dados/serie/"
SERIES = "bcdata.sgs.24363"
URL = BCB ~ SERIES ~ "/dados?formato=json"
printf "URL='%s'\n", URL
json = readfile(URL)
bundle b = jsongetb(json)
# the bundle b should contain an anonymous array of
# bundles, one per observation
if inbundle(b, "anon")
nobs = nelem(b.anon)
matrix vals = zeros(nobs,1)
strings S = array(nobs)
loop i=1..nobs -q
vals[i] = atof(b.anon[i].valor)
S[i] = b.anon[i].data
printf "%s %g\n", S[i], vals[i]
endloop
# Now, if you happen to know the data frequency
nulldata nobs --preserve
scalar mon, day, yr
sscanf(S[1], "%d/%d/%d", day, mon, year)
stobs = sprintf("%d:%02d", year, mon)
setobs 12 @stobs
series myname = vals
print myname -o
delete S
delete vals
endif
</hansl>
Allin