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
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.7k
Redash のいま / Redash in 2021
ariarijp
2
1.1k
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
470
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
FDEが実現するAI駆動経営の現在地
gonta
2
220
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1k
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
1
190
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
200
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
190
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.6k
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
380
今さら聞けない .NET CLI
htkym
0
140
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
150
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
110
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
240
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
440
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
600
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.7k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
sira's awesome portfolio website redesign presentation
elsirapls
0
310
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.2k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
420
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Building Adaptive Systems
keathley
44
3.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.7k
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