2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

jsonをPythonで扱う方法

Last updated at Posted at 2024-04-08

jsonとは

jsonとは、javascriptのデータフォーマットをもとにしたデータの持ち方のこと
jsonは{}と[]でデータを表している

jsonのまま表示させる

obj = {"item":"りんご","price":120}
#jsonのデータを作成している
json_text = json.dumps(obj,ensure_ascii=False)
#dumpsを使うことでjson形式へ変換
#ensure_ascii=Falseで「りんご」を日本語表記にできる
json_text

jsonをリスト化させる

text ='{"id":123,"is_student":true}'
#textの中へjson形式のデータを格納
obj = json.loads(text)
#loadを使うことでデータを辞書型として取り出せる
print(obj)

参考)https://www.youtube.com/watch?v=WsenyJ18ykU

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?