Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JSONataを使ってみよう Step Functionsが楽しくなる実践テクニック #dev...
Search
dafujii
September 03, 2025
Programming
1.3k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JSONataを使ってみよう Step Functionsが楽しくなる実践テクニック #devio2025
DevelopersIO 2025 Osaka 登壇資料です。
dafujii
September 03, 2025
More Decks by dafujii
See All by dafujii
大阪オフィスに Unitree Go2 がやってきたので Physical AI やってみた
dafujii
0
440
Software Design 定期購読のススメ
dafujii
1
4.9k
100均商品でスモールスタートを決めよう MixLeap Live LT #42 - 「デスク周りのDIY」
dafujii
0
1.2k
オフィスランチにこそ完全食
dafujii
0
2.6k
石油王よりもOSSコントリビュータを選んだ話
dafujii
0
780
チームサンドイッチマン ゼロカロリースキル #Alexaスキルアワード 2019
dafujii
1
160
Other Decks in Programming
See All in Programming
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
AmebaブログはKMPから卒業します
kmars0605
0
210
AWSに止められる覚悟してますか?
morizo_1984
2
540
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
330
[2026-10-14](C)Re:ゼロから始める異世界生活〜始まりの終わりと終わりの始まり〜
tosite
0
110
Performance Optimization With LLMs
xleitix
0
160
Agents on Rails - Rails at Scale 2026
irinanazarova
0
570
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
440
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
510
phperだってパンチカードでコーディングしたい
o0h
PRO
0
360
R8 の設定見直しでアプリサイズ削減
andpad
0
220
最近”作らせてる” ローカルAIアプリの話
akit37
0
480
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
It's Worth the Effort
3n
188
29k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Producing Creativity
orderedlist
PRO
348
41k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
410
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
630
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
400
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
930
Bash Introduction
62gerente
615
220k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Transcript
JSONataを使ってみよう Step Functionsが楽しく なる実践テクニック ふじい 製造ビジネステクノロジー部 スマートプロダクトチーム
2 • 2020年9⽉ ⼊社 ◦ サーバサイドエンジニアのお仕事 • 2023年3⽉ 育児休業取得 ◦ 育休⼀年取ってみた 〜4カ⽉⽬〜
◦ 育休⼀年取ってみた 〜13カ⽉⽬〜 • 2024年5⽉ 育児休業から復帰 • 2025年9⽉ ◦ DevelopersIO 2025 Osaka 登壇なう ◦ ⼊社してもう5年経ってる怖 部署 • 製造ビジネステクノロジー部 近況 • マリカーワールドで全キャラ、 全コスチューム解放完了! 資格: AWS 全部 All Cert: 2022, 2023, 2024, 2025 自己紹介 ふじい
今⽇話す内容について 3 ターゲット • まだ JSONPath を使っている⼈ • これから Step
Functions を触ろうとしている⼈ ゴール • Step Functions で JSONata を使ってみる
JSONata はいいぞ
【悲報】re:Growth 2024 OSAKAでJSONataについて話されていた 5 【朗報】使いまわせる https://dev.classmethod.jp/articles/re-growth-2024-osaka-jsonata/
6 https://dev.classmethod.jp/articles/re-growth-2024-osaka-jsonata/
7 https://dev.classmethod.jp/articles/re-growth-2024-osaka-jsonata/
8 https://dev.classmethod.jp/articles/re-growth-2024-osaka-jsonata/
9 https://dev.classmethod.jp/articles/re-growth-2024-osaka-jsonata/
10 https://dev.classmethod.jp/articles/re-growth-2024-osaka-jsonata/
JSONata で Fizz Buzz やってみた
1.各ステートで利⽤ 12 ステートマシンらしい⾒た⽬
1. 各ステートで利⽤ 13 "Items": "{% [1..1000] %}", "Choices": [ {
"Condition": "{% $states.input%15=0 %}", "Next": "15" },(略) ], "Default": "Default" "Output":{"output":"{% $states.input^(number).output %}"} "Output": { "number": "{% $states.input %}", "output": "{% $states.input %}" }
1. 各ステートで利⽤ 14 実⾏時間: 約26秒 状態遷移数: 2004
1. 各ステートで利⽤ 15 実⾏時間: 約26秒 状態遷移数: 2004
1. 各ステートで利⽤ 16 教訓 ループに気をつけよう (JSONata関係なく)
2. 1ステートで完結 17 これぞ JSONata ステートマシン 超シンプル
2. 1ステートで完結 18 { "output": "{% $map([1..1000], function($i) {\n $i
% 15 = 0 ? \"FizzBuzz\" :\n $i % 3 = 0 ? \"Fizz\" :\n $i % 5 = 0 ? \"Buzz\" :\n ($i)\n})\n %}" } $map([1..1000], function($i) { $i % 15 = 0 ? "FizzBuzz" : $i % 3 = 0 ? "Fizz" : $i % 5 = 0 ? "Buzz" : ($i) }) ※ダブルクオーテーションはエスケープ されるのでシングルクォーテーションの 使⽤をおすすめします。
2. 1ステートで完結 19 実⾏時間: 約0.1秒 状態遷移数: 3 めっちゃ速い! 課⾦も抑えられる!
JSONata にわくわくしてきました? • プログラミング構造はチューリング完全 • ループ処理を1ステート内で表現できれば、状態遷移数が節約できる • Lambda でしていた処理を表現できれば、処理時間の短縮ができる =>
つまり 料⾦の削減、処理時間の削減 ができる • AI に「⚪⚪の処理を JSONata で書いて」が通じる • (あと書いててちょっと楽しい) 20
JSONata で⽇付操作やってみた
和暦変換 • 22 https://dev.classmethod.jp/articles/step-functions-jsonata-japanese-era-date-conversion/
和暦変換 ($toWareki := function($year, $month, $day){( $eras := [ {"name":"令和","abbr":"R","start":{"year":2019,"month":5,"day":1}},
{"name":"平成","abbr":"H","start":{"year":1989,"month":1,"day":8}}, {"name":"昭和","abbr":"S","start":{"year":1926,"month":12,"day":25}}, {"name":"⼤正","abbr":"T","start":{"year":1912,"month":7,"day":30}}, {"name":"明治","abbr":"M","start":{"year":1868,"month":1,"day":25}}]; $compareDate := function($y1, $m1, $d1, $y2, $m2, $d2) { $y1 > $y2 ? 1 : $y1 < $y2 ? -1 : $m1 > $m2 ? 1 : $m1 < $m2 ? -1 : $d1 > $d2 ? 1 : $d1 < $d2 ? -1 : 0 }; $era := $eras[$compareDate($year, $month, $day, start.year, start.month, start.day) >= 0 ][0]; $era = null ? { "wareki": "不明", "warekiAbbr": "?", "year": $year } : ( $eraYear := $year - $era.start.year + 1; $displayYear := $eraYear = 1 ? "元" : $eraYear; { "wareki": $era.name & $displayYear & "年", "warekiAbbr": $era.abbr & $displayYear, "year": $year, "month": $month, "day": $day } ) )}; $toWareki($states.input.year, $states.input.month, $states.input.day);) 23
うるう年判定 24 $fromMillis( $toMillis( $states.input.year & "-02-28T00:00:00" ) + 60*60*24*1000,
"[M1]" ) = "2"
JSONata で ⚪⚪ やってみた
DevelopersIO で JSONata タグの記事を⾒てね 26 https://dev.classmethod.jp/tags/jsonata/
注意点
テストがしにくい 28 CDK で Step Functions + Lambda の場合 •
Lambda 関数のコードに対して単体テストが書きやすい でも JSONata のテストとなると……
テストがしにくい 29 CDK で Step Functions で JSONata ステートのテストの場合 •
変更するたびにデプロイして、マネコンでポチポチはつらい • LocalStack は Step Functions の JSONata 対応済み ◦ ※ 無料版に Step Functions が含まれている 🙌 ◦ Lambda 関数のテスト環境構築するより⼿間 • テストを記述しようとすると、AWS SDK で StartExecution API や TestState API を叩くテストになる(統合テスト)
Exerciser と Step Functions で挙動が異なる 30 $toMillis("2025-02-29") • JSONata Exerciser
は動く: 1677628800000 (3/1) • Step Functions だとエラーになる ◦ うるう年(2024-02-29)、うるう⽇以外(2023-02-28)なら成功 $toMillis("2025-02-29T00:00:00") • 時間まで記載すればStep Functions でエラーにならない • ただし JSONata Exerciser とは結果が異なる ◦ ブラウザのタイムゾーンが使⽤されるため
うるう年判定(再) 31 $fromMillis($toMillis("2023-02-29T00:00:00"), "[M1]") = "2" • 2/29 をタイムスタンプに変換して再度⽇付に変換し2⽉ならうるう年 •
JSONata Exerciser ならこれだけでいい • Step Functions だとなぜかタイムスタンプ変換後 2/28 になる $fromMillis($toMillis("2023-02-28T00:00:00")+60*60*24*1000,"[M1]")="2" • 2/28 の翌⽇が2⽉ならうるう年 • Step Functions で動かそうとするとこうする必要があった • JSONata Exerciser だとブラウザのタイムゾーンを使⽤するため常 true
うるう年判定(再) 32 Step Functions でも JSONata Execiser でも動かすには • $fromMillis($toMillis("2023-02-28T00:00:00Z")+60*60*24*1000,
"[M1]") = "2" • ⽇付だけではなく時分秒まで記述する • タイムゾーンが UTC であると Z を明記する • 2/29 ではなく、 2/28 + 1⽇をタイムスタンプに変換する • JSONata Exerciser で動いても Step Functions で動くとは限らない
まとめ
JSONata はいいぞ 34 使ってみよう • JSON をクエリするだけでなく、計算や⽇付操作など処理ができる • JSONata Exerciser
で気軽に試せる ◦ でも JSONata Exerciser で動いても、Step Functions で動かない パターンがある ◦ JSONata を試す⽤のステートマシンを作っておくと便利
JSONata はいいぞ 35 でも効果的に使おう • うまく使えば料⾦削減、実⾏時間削減できる • テスタビリティが低いので使い所を⾒極めよう JSON の加⼯に徹する、変更の少ない箇所、
組み込み関数を有効活⽤しプログラミングを頑張らない ⾮ビジネスロジック、Lambda を使うほどでもない処理、 既存の JSONPath の Step Function は無理に移⾏しない、など ぜひ使ってみてください!
None