Apr 13, 2013 python

Convert json text into python data

import json
out=json.loads("...JSON texts....")

Load json text file

import json

with open('data.json') as data_file:    
data = json.load(data_file)

convert data into json

json_str=json.dumps( my_data )

pretty-print

print json.dumps({'4': 5, '6': 7}, sort_keys=True,
...                  indent=4, separators=(',', ': '))
{
    "4": 5,
    "6": 7
}

JSON - alternative json library

Use 3rd party json for faster alternatives ultrajson (fastest) or simplejson instead of json package.