Update: 9/12/2016 WG have changed the JSON schema used - the technique still works fine, but the JSON path details have changed.
=JsonPathOnUrl(K3,"schName") - now pulls the school name for example.
My Local School is useful if you want to look at a particular school in detail, but what the site explicitly does not do is allow you to compare schools or to extract the data so that you can on process it (with some Excel-fu).
Fortunately, the site is standards based and uses JSON to pull data from their back end server. This means that once we discover what Urls the site calls, we can execute those JSON calls and pull the data straight into Excel.
As I posted before, the json URLs are of the form
http://mylocalschool.wales.gov.uk/schools/6734067.json where the 6734067 is the unique school number. (This you should know, however the Welsh Government publish a list of all schools in Wales - so you can download and get them all).
Viewing the JSON
If you follow the URL above you will see:
Clearly data – and we can just about make out that there is some order to it.
{“school":{“basicDetails":{“name": “St Cyres School" …….etc
It’s not much of a leap to consider these as field names and data in a data base. And indeed that’s sort of, kinda what JSON is.
Using this JSON viewer you can begin to see the structure of the file. Clicking on the top left viewer option and the JSON changes to a TREE VIEW:
Where we can see {}JSON, {}School – the {} braces incicate what is called a JSON node.
For example, here we can see {}JSON.school.pupilPopulation.pupils.all - leads us to data for the school population.
0:154, 1:181 etc up to 7:1184
Under {}pupils the all node has square brackets [] indicating that this is an array. The first element in the array is 0 and corresponds to year 7 (as this is a secondary school). The final array entry [7] = 1184, which is the total for the entire school.
Some schools will have extra nodes, corresponding to Year 14 or for 3-18 schools, additional years. Importantly, the final array element is always the total for the school.
To select a particular nodal element, we enclose it in square brackets, so:
{}JSON.school.pupilPopulation.pupils.all[6] selects array element 6 or 98 in this case.
JSON in Excel
There are a number of ways of getting JSON data in Excel (and particularly for Excel 2013) – for me, the easiest and most reliable way is to install the (free) splendid add-in
SeoTools (marketed for webmasters).
When installed, SeoTool adds some extra functions to Excel. The function we want is ,JsonPathOnUrl() – which literally reaches out to a url and pulls in the data.
So, =JsonPathOnUrl(http://mylocalschool.wales.gov.uk/schools/6734067.json,"$school.pupilPopulation.pupils.all[5]“) reaches out the url and pulls in all[5] – in this case, 122 into a cell.
If we change the URL to a cell reference, we can build a sheet that has a URL for every school in Wales, and pulls in what ever data we want for each school.
Accessing the last element in an array
Getting nodal data is easy – .all[5] for example. But for certain data we want the LAST element. This is tricky and some Excel-fu is needed.
With the data for the .all array in J10, (called by =JsonPathOnUrl(D10,"$school.pupilPopulation.pupils.all") (D10 contains the URL for the JSON file).
J10 will contain (in my case) -
“[10, 12, 14, 12, 21, 19, 27, 25, 55, 58, 55, 57, 57, 46, 32, 500]" – the [] indicating an array.
This formula extracts the last element in array J10:
Q10 =MID(J10,FIND(“@",SUBSTITUTE(J10,",","@",LEN(J10)-LEN(SUBSTITUTE(J10,",",""))))+1,99)
Q10 = 500]
We now need to remove the trialling ] with:
R10=MID(Q10,1,LEN(Q10)-1)
R10=500
S10=CLEAN(R10)
S10=500
This is the total number of pupils in the school and is contained in the [].all array as the last element.
Moving forward
Using this technique it is possible to build an Excel sheet that pulls from My Local School ALL the data for every school in Wales (primary, secondary, special, nursery) – all leveraged using the power of JSON and some Excel-fu.
If any reader would like an example Excel sheet – pop a comment below and I’ll tidy up my working code.
Comment Wall
You need to be a member of Classroom 2.0 to add comments!
Join Classroom 2.0