Custom Json (de)serialisation?
I'm porting some code from .Net to python. At one point, we need to translate arbitrarily complex json from one format to another. Eg: {'Query': { 'Boolean': {
Solution 1:
You can subclass the default JSONEncoder.
From: http://docs.python.org/2/library/json.html
"To use a custom JSONEncoder subclass (e.g. one that overrides the default() method to serialize additional types), specify it with the cls kwarg; otherwise JSONEncoder is used."
http://docs.python.org/2/library/json.html#json.JSONEncoder
Example of usage: Custom JSON encoder in Python 2.7 to insert plain JavaScript code
Post a Comment for "Custom Json (de)serialisation?"