Python has two data types that, together, form the perfect tool for working with JSON: dictionaries and lists. Let’s explore how to:
Python ships with a powerful and elegant JSON library. It can be imported with:
import json
Decoding a string of JSON is as simple as json.loads(…)
(short for load string).
It converts:
null
will be converted into Python’s None
typeHere’s an example of json.loads
in action:
>>> import json
>>> jsonstring = '{"name": "erik", "age": 38, "married": true}'
>>> json.loads(jsonstring)
{'name': 'erik', 'age': 38, 'married': True}
#python #data-science