2013-05-01 40 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=(',', ': ')) 
相關問題