In [1]:
import IPython
from IPython.core.display import JSON
import json

d = {"foo": "bar"}
JSON(d if IPython.version_info[0] >= 3 else json.dumps(d))


Out[1]:
<IPython.core.display.JSON object>

In [2]: