This is an old revision of the document!
json debugging, colored output
#!/usr/bin/python
import json
import requests
from pprint import pprint
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import Terminal256Formatter
from pprint import pformat
def pprint_color(obj):
print highlight(pformat(obj), PythonLexer(), Terminal256Formatter())
data = {
u'type': u'requiesttype',
u'searchkey': 'string that is searched for'}
url = 'http://url.to/submit/to'
r = requests.post(
url,
data=json.dumps(data))
try:
pprint_color(
json.loads(r.text))
except ValueError:
print r.text
