Earlier this week we told you about our new lighter JSON-STAT format that we’re supporting in the API. Although much lighter and simpler than SDMX, there are still a few different sections in the response data, for many applications you might just be interested in ‘The raw numbers’
In this post, we’re going to walk you through a simple bit of code for requesting some data and then turning that into ‘just the raw numbers’. In this example, we want to know what the split of males and females was for England and Wales in the 2011 census. All we really want here is 2 numbers (maybe 3 if we want the total as well!)
This example is written using python but all we’re using is an HTTP library to make the request and a JSON library to parse the data, so it should be possible to do the same sort of thing in most other languages.
First of all we need to get setup:
Next we’re going to make the request to the API
Ok let’s take a look at what the API returned us:
Wow! That’s still quite a lot of stuff for just 3 numbers, let’s see if we can process that down:
OK, now we’ve got something that looks a lot simpler we can use in our app 🙂
If you want to grab that piece of code as a nice clean single script, then it can be downloaded from https://gist.github.com/sammachin/671f90c15ec6331598e5
Was this helpful? what sort of posts would you like to see about our API in future? let us know by leaving a comment.