JSON data reader
JSON data reader reads files whose extension is .json
.
[1]:
import tempfile
from pprint import pprint
from galactic.io.data.core import PopulationFactory
data = """\
{
"#1": {
"name": "Galois",
"firstname": "Évariste"
},
"#2": {
"name": "Wille",
"firstname": "Rudolf"
}
}
"""
with tempfile.NamedTemporaryFile(mode="w+t", suffix=".json") as file:
file.write(data)
file.seek(0)
population = PopulationFactory.create(file)
pprint({key: dict(value) for key, value in population.items()})
{'#1': {'firstname': 'Évariste', 'name': 'Galois'},
'#2': {'firstname': 'Rudolf', 'name': 'Wille'}}