I'm working with the following data:
[{"title": null, "metric1": 361429, "metric2": 36,},{"title": null, "metric1": 253798, "metric2": 48}]
When I attempt to assign this data to a variable in Python (with the aim of parsing it out), I receive the following error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'null' is not defined
From my research, it appears that the None
is Python's null
. What I'm wondering is, is it possible to change the null
's in my data to None
's using Python?
I've tried creating a string out of the data, assigning it to data
, and replacing the null
's that way:
data = data.replace('null','None')
but that results in a string of the data itself:
data = '[{"title": None, "metric1": 361429, "metric2": 36,},{"title": None, "metric1": 253798, "metric2": 48}]'
and I can't figure out how to turn it from a string back into JSON.
EDIT: I am copying and pasting this data into the Python interpreter from a separate source.