Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PythonでJSON Schemaを扱う
Search
aoken
August 28, 2020
Programming
0
65
PythonでJSON Schemaを扱う
aoken
August 28, 2020
Tweet
Share
Other Decks in Programming
See All in Programming
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
CSC307 Lecture 07
javiergs
PRO
0
550
AIエージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
5
460
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
130
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
610
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.1k
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
110
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
180
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
280
AI巻き込み型コードレビューのススメ
nealle
1
280
CSC307 Lecture 01
javiergs
PRO
0
690
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Being A Developer After 40
akosma
91
590k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
260
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
Designing for humans not robots
tammielis
254
26k
The agentic SEO stack - context over prompts
schlessera
0
640
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
69
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
190
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
220
Transcript
PythonでJSON Schemaを扱う PyCon 2020 ビザスク スポンサーブース LT Kenya Aono
お前、誰よ 青野 剣矢(Aono Kenya) - ビザスク フルサポート開発チーム所属 - Python, Django
- Typescript, Vue.js, AngularJS
このLTのアジェンダ - JSON Schemaってなんだ? - PythonでJSON Schemaを活用してみる
JSON Schemaってなんだ?
JSON Schemaとは - JSONの構造を定義するための規格 - APIの仕様書として使ったり - HTTP Content-type application/json
のバリデーションとして使った り - 様々なプログラミング言語で扱うことができる
JSON Schemaを定義してみる { "name": "Kenya Aono", "age": 29, "team": "fullsupport-dev"
"startDate": "2019-04-01" }
{ "$schema": "http://json-schema.org/draft-07/schema", "type": "object", "properties": { "name": { "type":
"string" }, "age": { "type": "integer" }, "team": { "type": "string" }, "startDate": { "type": "string" } } }
enumで選択肢を定義する "team": { "type": "string", "enum": [ "fullsuport-dev", "advisor-dev", "lite-dev"
] },
正規表現でパターンを定義する "startDate": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" }
PythonでJSON Schemaを扱う
pip install jsonschema from jsonschema import validate, ValidationError import schema
# さっき定義したスキーマとします data = { 'name': 'Kenya Aono', 'age': 29, 'team': 'fullsuport-dev', 'startDate': '2019-04-01', } try: validate(data, schema) except ValidationError as e: print(e.message)
{ "$schema": "http://json-schema.org/draft-07/schema", "type": "object", "required": [ "name", "age", "gender"
], "properties": { "name": { "type": "string" }, "age": { "type": "integer" }, "team": { "type": "string" }, "startDate": { "type": "string" } } }
jsonschema data = { 'name': 'Kenya Aono', 'age': '29sai', 'team':
'fullsuport-dev', 'startDate': '2019-04-01', } try: validate(data, schema) except ValidationError as e: print(e.message) Invalid JSON - 'age' is not of type 'integer'
まとめ - JSON Schemaを使えばJSONの構造を明確化することができる - PythonでJSON Schemaを扱いたいなら`pip install jsonschema`!