1. JSON Load and Dump
import json def JsonLoadString(data): return json.loads(data) def JsonLoadFile(filename): data = None with open(filename) as f: data = json.load(f) return data def JsonDumpMinify(data): return json.dumps(data) def JsonDumpPretty(data): return json.dumps(data,sort_keys=True,indent=4) if __name__ == "__main__": print( JsonDumpMinify(['foo', {'bar': ('baz', None, 1.0, 2)}]) ) print( JsonDumpPretty({'4': 5, '6': 7} )) print( JsonLoadString('["foo", {"bar":["baz", null, 1.0, 2]}]') ) print( JsonLoadFile('a.json') )
댓글 없음:
댓글 쓰기