반응형

dictionary 를 json 으로 변환

 

https://docs.python.org/2/library/json.html

 

18.2. json — JSON encoder and decoder — Python 2.7.18 documentation

18.2. json — JSON encoder and decoder JSON (JavaScript Object Notation), specified by RFC 7159 (which obsoletes RFC 4627) and by ECMA-404, is a lightweight data interchange format inspired by JavaScript object literal syntax (although it is not a strict

docs.python.org

import json

dict1 = { 'name' : 'song', 'age' : 10 }

print "dict1 = %s" % dict1
print "dict1 type = %s" % type(dict1)
print "================"

# CONVERT dictionary to json using json.dump
json_val = json.dumps(dict1)


print "json_val = %s" % json_val
print "json_val type = %s" % type(json_val)
반응형

+ Recent posts