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.4k
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
Transcript
36 slides
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
More Decks by dafujii
See All by dafujii
大阪オフィスに Unitree Go2 がやってきたので Physical AI やってみた
dafujii
0
600
Software Design 定期購読のススメ
dafujii
1
5k
100均商品でスモールスタートを決めよう MixLeap Live LT #42 - 「デスク周りのDIY」
dafujii
0
1.2k
オフィスランチにこそ完全食
dafujii
0
2.6k
石油王よりもOSSコントリビュータを選んだ話
dafujii
0
800
チームサンドイッチマン ゼロカロリースキル #Alexaスキルアワード 2019
dafujii
1
170
Other Decks in Programming
See All in Programming
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
280
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
610
Stage 3でも仕様は変わる。アプリケーション開発者のためのTC39プロセスの読み方
bicstone
1
420
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
330
将来の標準フォーマッター?ktfmtを深堀る
t45k
1
250
AIコーディング時代のKotest ユニットテストから APIレベルの仕様固定化テストへ
ooga04
0
340
Beyond Chatbots: Agentic UI with Open Standards @W-JAX 2026, München
manfredsteyer
PRO
0
130
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.6k
Going Full Circle with Virtual Graphs and Relational Databases
michaelsimons
1
120
正解の無い問題を 「できるだけ上手く」解く ヒューリスティックで感性を磨こう。〜現実課題をプログラミングで解きあうコミュニティについて〜
allegrogiken
0
120
Jujutsu で毎日のバージョン管理に「安心」と「直感性」を
oukayuka
0
110
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
150
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
37
7.5k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
410
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
3k
Chasing Engaging Ingredients in Design
codingconduct
0
410
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
570
Typedesign – Prime Four
hannesfritz
42
3.2k
Everyday Curiosity
cassininazir
0
420
The SEO Collaboration Effect
kristinabergwall1
1
630
Side Projects
sachag
456
43k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.9k
Speed Design
sergeychernyshev
33
2.3k