Not sure if you hadn't got to it yet but don't forget to write tests for this function. May be easier to do the json loading outside this function then you can just pass in nice json objects for your tests