JSON Data Goodness on the new ONS (Office for National Statistics) Website

Via the @ONSDigital blog (http://blog.ons.digital/2016/02/25/new-ons-website-launched/, it seems that the new Office for National Statistics website, which publishes the UK’s official government statistics, has just been released in all its glory.

One thing I noticed was that it’s now trivial to get hold of data, in JSON format, from a statistics page by adding /data to the end of a stats page URL.

For example, the data behind the Consumer Price Index page:

https://www.ons.gov.uk/economy/inflationandpriceindices/timeseries/d7g7

can be found at:

https://www.ons.gov.uk/economy/inflationandpriceindices/timeseries/d7g7/data

Data can also be downloaded in CSV and XLS formats using another derivable URL. For example, to download the data as CSV:

http://www.ons.gov.uk/generator?format=csv&uri=/economy/inflationandpriceindices/timeseries/d7g7

Use the value xls rather than csv to get the spreadsheet file.

Another nice feature is that the alphabetic listing of statistics:

http://www.ons.gov.uk/atoz?az=a

can also be accessed in a JSON data format by adding the /data path element:

http://www.ons.gov.uk/atoz/data?az=a

(Paged) search results can also be returned in JSON format:
https://www.ons.gov.uk/search/data?q=unemployment&page=12

Search results can also be narrowed down (following the tabs on the search results HTML page) from All to Data or Publications:

http://www.ons.gov.uk/searchdata/data?q=unemployment

http://www.ons.gov.uk/searchpublication/data?q=unemployment

It’s also possible to get time series charts as image URLs of the form:

https://www.ons.gov.uk/employmentandlabourmarket/peopleinwork/employmentandemployeetypes/timeseries/lf24/linechartimage?series=&fromMonth=01&fromYear=1971&toMonth=12&toYear=2015&frequency=months

(The date range filters don’t seem to work if applied to the /data URLs?)

Now I just need some time to play!

PS I’ve just popped a gist containing some python code that represents a first start at grabbing the data from the JSON feeds here: https://gist.github.com/psychemedia/ca7b981f2bbd45377b44

One comment

  1. Paul Bivand (@LWpaulbivand)

    Small pain. The numbers are rounded to the published total.

    This means that if you calculate changes, they won’t be the same as the ONS published changes.

    e.g. The employment rate (LF24), value in JSON 74.1, in the xls download (file A02….xls) this is 74.1177206989384. Which happens to be the figure you get if you do the same calculation in the raw dataset (or the NSA version would be).

    If I calculate changes using the single decimal place version they are different from the large numbers of decimal places version, after rounding to the single decimal place.

    So, as for now, I’m sticking to the xls formats although the downloads seem to have got an order of magnitude more difficult.