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
Which way is better to handle JSON with Crystal
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Takuya Arita
August 01, 2015
Programming
1.1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Which way is better to handle JSON with Crystal
Takuya Arita
August 01, 2015
More Decks by Takuya Arita
See All by Takuya Arita
Hosted Redash の EOL と移行ツール redash-migrate / You should know about Hosted Redash EOL and redash-migrate
ariarijp
0
3.3k
Redash で踏み出す BI 導入はじめの一歩 / DataEngineeringStudy Redash
ariarijp
1
2.8k
Redash のいま / Redash in 2021
ariarijp
2
1.2k
Redash 導入・運用を4年ぐらいやって変わったこと・変わらなかったこと / Changed and unchanged things with Redash and me
ariarijp
0
1.4k
5年前の自分に伝えたい広告 API 周辺の歩き方 / SOT Tech Night vol.1
ariarijp
1
550
使われていない、を知る / How do we know unused things in the real world?
ariarijp
0
480
MULTI_ORG について / What is MULTI_ORG in Redash
ariarijp
1
3.9k
あらためて振り返る Redash の使いどころ / Why I strongly recommend Redash
ariarijp
2
1.3k
PHP Data Structures
ariarijp
1
580
Other Decks in Programming
See All in Programming
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
540
Hono + Inertia + React で LP を構築した話
oukayuka
2
150
不幸な GC
chencmd
0
680
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
160
レビュー履歴をAIに食わせて、 Compose移行を加速するs
shihochan
0
200
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
240
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
270
AIに既存システムを理解させる技術 ~レガシーを見捨てないハーネスエンジニアリング入門~
ochtum
0
140
「つくるAI」だけではバグは見つからない ~テストに必要な「見つけるAI」を分離させる戦略~
mfunaki
0
160
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
370
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
160
Android CLI
fornewid
0
230
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
41
2.7k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.9k
Designing Experiences People Love
moore
143
24k
Between Models and Reality
mayunak
4
400
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
270
The Mindset for Success: Future Career Progression
greggifford
PRO
0
470
Leo the Paperboy
mayatellez
8
2.2k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
350
Typedesign – Prime Four
hannesfritz
42
3.1k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
440
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
Transcript
Which way is better to handle JSON with Crystal @ariarijp
w !BSJBSJKQ 5BLVZB"SJUB w $PDPMBCMF *OD w 4PGUXBSF&OHJOFFS "CPVUNF
Today’s Lightning talk
The idea from ཬ.rb 1st anniversary https://nishinipporirb.doorkeeper.jp/events/25958
None
I talked about my first Crystal program
Parse JSON using Crystal
None
I compared Ruby and Crystal
None
Crystal is awesome. But I don’t like Java like type
casting
Next morning
None
@asterite commented on my repository (Amazingly, @asterite read Japanese!) https://github.com/ariarijp/ninirb-1st-anniversary-lt-crystal/commit/2d0062c4a1dc4cabaeb6884591c1771d768c0ce8
As a result
The legacy way require "http/client" require "json" place = ARGV[0]
url = "http://api.openweathermap.org/data/2.5/weather?q=#{place}" resp = HTTP::Client.get(url) weather = JSON.parse(resp.body) pp (((weather as Hash)["weather"] as Array)[0] as Hash)["main"] puts "-" * 80 pp weather
Crystal way require "http/client" require "json" class WeatherResponse json_mapping({ weather:
Array(Weather), }) class Weather json_mapping({ id: Int32, main: String, description: String, icon: String, }) end end place = ARGV[0] url = "http://api.openweathermap.org/data/2.5/weather?q=#{place}" resp = HTTP::Client.get(url) puts "-" * 80 weather_resp = WeatherResponse.from_json(resp.body) pp weather_resp pp weather_resp.weather[0].main
Use JSON Mapping!
Crystal is Awesome!
end