Parsing IATI data from JSON using Ruby

Hello, I’m trying to parse IATI data from JSON format using Ruby rather than Python. Has anyone done this? I’ve got halfway using JSON that I downloaded via OIPA but I’m getting an unexpected token error. Anyone know what that means? This didn’t work (found on stack overflow):

JSON.parse somehow did not like UTF-8-encoded files. Encode the files to ASCII (= ISO 8859-1)

Any help appreciated!

I’m pretty sure that @siemvaessen or @VincentVW could help you with that :)…

Hi Sara,

We don’t do Ruby, so can’t help you out there.

When you say ‘halfway using JSON & the unexpected token error’ => do you mean an OIPA unexpected token error or a Ruby error?

Siem

DevTracker is an Sinatra (Ruby) app that runs on the OIPA API, maybe there’s suggestions to be found there; https://github.com/DFID/devtracker-from-api/search?utf8=✓&q=json.parse

I’ll also mention @r_clements here (developer on DevTracker).

Hi Sara, you can find some (parsing examples) [https://github.com/DFID/devtracker-from-api/blob/master/helpers/country_helpers.rb] in the helpers directory of the devtracker-from-api code.

I have userd the country_helpers example as I think that that one is pretty intuative but most of the files in the helpers directory would contain at least a few OIPA api calls.

[parsing examples] (https://github.com/DFID/devtracker-from-api/blob/master/helpers/country_helpers.rb)

Hi @siemvaessen it’s a Ruby error.

Hi Ross and Vincent @r_clements @VincentVW, thanks for the link, exactly what I was looking for!

Sarah

Hey Sarah - I just remembered that I also wrote a little Ruby/Rails application to pull IATI data from the Registry and display it. It’s about 5 years old and the code might not be that nice but this is the main bit that gets data from the Registry and parses it (from XML) into a database – perhaps it is helpful:

There’s a very brief write-up on the aidinfo labs site:
https://web.archive.org/web/20110927111130/http://www.aidinfolabs.org/archives/416

Incidentally, that link was via the internet archive - such a shame that the aidinfo labs site has been taken down, there’s a load of useful information in there; can someone from DI try and get it back up again, even just as a historical record?

Thanks for flagging this @markbrough - I’ll look into this and report back shortly.

1 Like