Note
This documentation is for a development version of IPython. There may be significant differences from the latest stable release (1.2.1).
Utilities to manipulate JSON objects.
Rekey a dict that has been forced to use str keys where there should be ints by json.
parse an ISO8601 date string
If it is None or not a valid ISO8601 timestamp, it will be returned unmodified. Otherwise, it will return a datetime object.
extract ISO8601 dates from unpacked JSON
squash datetime objects into ISO8601 strings
default function for packing datetime objects in JSON.
b64-encodes images in a displaypub format dict
Perhaps this should be handled in json_clean itself?
Parameters: | format_dict : dict
|
---|---|
Returns: | format_dict : dict
|
Clean an object to ensure it’s safe to encode in JSON.
Atomic, immutable objects are returned unmodified. Sets and tuples are converted to lists, lists are copied and dicts are also copied.
Note: dicts whose keys could cause collisions upon encoding (such as a dict with both the number 1 and the string ‘1’ as keys) will cause a ValueError to be raised.
Parameters: | obj : any python object |
---|---|
Returns: | out : object
|
Examples
>>> json_clean(4)
4
>>> json_clean(list(range(10)))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> sorted(json_clean(dict(x=1, y=2)).items())
[('x', 1), ('y', 2)]
>>> sorted(json_clean(dict(x=1, y=2, z=[1,2,3])).items())
[('x', 1), ('y', 2), ('z', [1, 2, 3])]
>>> json_clean(True)
True