Skip to content

Instantly share code, notes, and snippets.

@makotoworld
Created December 19, 2012 04:23
Show Gist options
  • Save makotoworld/4334367 to your computer and use it in GitHub Desktop.
Save makotoworld/4334367 to your computer and use it in GitHub Desktop.
python で json を解析、出力する
import simplejson
## 書き出し
sample = {"@title": "みんなのPython", "author": "柴田淳", "pub": ["SoftBank Creative", "2006"]}
file = open("sample.json", "w")
simplejson.dump(sample, file, indent=3)
## sample.jsonの中身
#{
# "@title": "みんなのPython",
# "pub": [
# "SoftBank Creative",
# "2006"
# ],
# "author": "柴田淳"
#}
## 読み込み
file = open("sample.json")
a = simplejson.load(file)
a["@title"]
# >> u"みんなのPython"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment