2013-05-01 42 views

回答

6

json.tool确实不外乎:

with infile: 
    obj = json.load(infile) 
with outfile: 
    json.dump(obj, outfile, sort_keys=True, 
       indent=4, separators=(',', ': ')) 

其中infileoutfile缺省值分别stdinstdout

如果你有一个对象已经,你可以得到同样的效果:

import json, sys 

json.dump(obj, sys.stdout, sort_keys=True, 
      indent=4, separators=(',', ': ')) 

print json.dumps(obj, sort_keys=True, 
       indent=4, separators=(',', ': ')) 
相关问题