Python: How json dumps None to empty string -


Do I have to encode Python's none in Jason as an empty string? Below is the default behavior of json.dumps .

  & gt; & Gt; & Gt; Import json & gt; & Gt; & Gt; Json.dumps (['foo', {'bar': ('baz', none, 1.0, 2)}] '[foo', {"bar": ["baz", null, 1.0, 2]} ] '  

Should I overwrite the Jason Encoder method or is there any other way?

Thank you!

Edit

Input data is not as simple as that, on every request it can be changed into different data structures. It is difficult to write a function to change the data structure.

In the object you are encoding, use any Instead of empty string.

Here is an unwanted function that runs through a series of nested dictionaries to change any value to . '. Adding support for lists and tuples has left the reader as an exercise. :)

  Import Copy DR (X): ret = copy.deepcopy (x) # Clear all values ​​for the ifinstance (x, dict) dictionaries: ret.items () In retro.items () v: ret [k] = clear (v) # handle none if x == none: ret = '' # end scrubbing return rate    

Comments