This documentation is for an old version of IPython. You can find docs for newer versions here.

Module: utils.jsonutil

Utilities to manipulate JSON objects.

7 Functions


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?


format_dict : dict

A dictionary of display data keyed by mime-type


format_dict : dict

A copy of the same dictionary, but binary image data (‘image/png’, ‘image/jpeg’ or ‘application/pdf’) is base64-encoded.


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.


obj : any python object


out : object

A version of the input which will not cause an encoding error when encoded as JSON. Note that this function does not encode its inputs, it simply sanitizes it so that there will be no encoding errors later.