Skip to content Skip to sidebar Skip to footer

Nulls, Instead Of Nones, In Json Data With Python

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

Solution 1:

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).

Solution 2:

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

Just

importjsonparsed_data= json.loads(data)

Post a Comment for "Nulls, Instead Of Nones, In Json Data With Python"