Nulls, instead of Nones, in JSON Data with Python

Much simpler!

Just assign None to null before assigning that list to a variable:

null = None
var = [{"title": null, "metric1": 361429, "metric2": 36,},{"title": null, "metric1": 253798, "metric2": 48}]

Then you won't need to do the rather unnecessary conversion to a string (and back to a Python object with json.loads) only to replace null by None.

But that is only really necessary if you're copy-pasting that code from some source. Otherwise, the canonical answer is to use json.loads (or json.load).


As is mentioned above, you don't need to replace "null" for "None"

Just

import json
parsed_data = json.loads(data)