I have a json file containing NZ regions and towns:
{
"region": [
{
"region_name": "northland",
"towns": [
"whangarei",
"paihia",
"russel"
]
},
{
"region_name": "auckland",
"towns": [
"auckland",
"porirua"
]
}
]
}
I have also defined a a Region class to deserialize this file:
class Region:
def __init__(self):
self.region_name = ''
self.towns = []
I want to convert the above json file to an array of Region, this is what I have tried:
import json
def get_nz_regions():
with open('location/nz_regions.json') as json_file:
nz_regions = json.load(json_file)
# return an array of Region