In [ ]:
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))

In [ ]: