stumped221
stumped221

Reputation: 99

Python 2.7 replace all instances of NULL / NONE in complex JSON object

I have the following code..

.... rest api call >> response

rsp = response.json()

print json2html.convert(rsp)

which results in the following

error: Can't convert NULL!

I therefore started looking into schemes to replace all None / Null's in my JSON response, but I'm having an issue since the JSON returned from the api is complex and nested many levels and I don't know where the NULL will actually appear.

From what I can tell I need to iterate over the dictionary objects recursively and check for any values that are NONE and actually rebuild the object with the values replaced, but I don't really know where to start since dictionary objects are immutable..

Upvotes: 0

Views: 302

Answers (1)

Michel Müller
Michel Müller

Reputation: 5705

If you look at json2html's source it seems like you have a different problem - and the error message is not helping.

Try to use it like this:

print json2html.convert(json=rsp)

btw. because I've already contributed to that project a bit I've opened up the following PR due to this question: https://github.com/softvar/json2html/pull/20

Upvotes: 1

Related Questions