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
SBJson 4: Don't make me wait!
Search
Stig Brautaset
March 05, 2014
Programming
0
410
SBJson 4: Don't make me wait!
How SBJson 4 can help you get happy users.
Stig Brautaset
March 05, 2014
Tweet
Share
More Decks by Stig Brautaset
See All by Stig Brautaset
Delighting your users with SBJson 4
stig
1
1.3k
Other Decks in Programming
See All in Programming
PC-6001でPSG曲を鳴らすまでを全部NetBSD上の Makefile に押し込んでみた / osc2025hiroshima
tsutsui
0
200
認証・認可の基本を学ぼう後編
kouyuume
0
250
gunshi
kazupon
1
120
LLM Çağında Backend Olmak: 10 Milyon Prompt'u Milisaniyede Sorgulamak
selcukusta
0
140
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
140
Giselleで作るAI QAアシスタント 〜 Pull Requestレビューに継続的QAを
codenote
0
310
AtCoder Conference 2025
shindannin
0
770
生成AI時代を勝ち抜くエンジニア組織マネジメント
coconala_engineer
0
28k
TestingOsaka6_Ozono
o3
0
180
SwiftUIで本格音ゲー実装してみた
hypebeans
0
510
LLMで複雑な検索条件アセットから脱却する!! 生成的検索インタフェースの設計論
po3rin
4
990
マスタデータ問題、マイクロサービスでどう解くか
kts
0
150
Featured
See All Featured
The agentic SEO stack - context over prompts
schlessera
0
570
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
[RailsConf 2023] Rails as a piece of cake
palkan
58
6.2k
Building AI with AI
inesmontani
PRO
1
580
Become a Pro
speakerdeck
PRO
31
5.7k
Agile that works and the tools we love
rasmusluckow
331
21k
Designing Powerful Visuals for Engaging Learning
tmiket
0
190
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
21
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
0
1.8k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
400
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
4 Signs Your Business is Dying
shpigford
187
22k
Transcript
SBJson 4: Don’t make me wait! Stig Brautaset ~ @stigbra
Who am I? Started SBJson in 2007. Compulsively tinkered with
it since.
Fun facts 7 years on • 1012 commits • 4
major releases • 30 contributors • 3247 “stars” • 688 “forks”
–Every non-trivial app, ever. “Download a list of records &
display them to the user.”
What’s more important to your users? • Time until they
see the last record? • Or until they see the first?
The trouble with pagination • Repeated connection overhead • Records
fall in the cracks between pages • Records appear on two consecutive pages
Download-then-parse Time to first record Time to last record
Chunked delivery Time to first record Time to last record
Multi-core chunked delivery Time to first record Time to last
record
Relative time to first record 0 1.25 2.5 3.75 5
1 record 2 records 3 records 4 records 5 records Chunked delivery Traditional
NSJSONSerialisation • Supports NSStream! • But can’t do chunked delivery.
• We can do better!
SBJson 3 • Chunked delivery since June 2011 :-) •
But it was confusing and cumbersome to use… :-/ • …requiring multiple delegates chained together :-(
SBJson 4 • Drops category & OO interfaces • Focus
on chunked delivery • Introduces a block-based interface • Built specifically for two primary use cases
Multi-root JSON [1,2,3] {“foo”:42} [true,false]
Multi-root JSON id parser = [SBJson4Parser multiRootParserWithBlock:block errorHandler:eh];
Multi-root JSON [parser parse:data("[]{")]; // calls block(@[]) [parser parse:data("}[]"]; //
next part of stream // calls block(@{}) // calls block(@[])
Multi-root JSON [parser parse:data("[]{")]; // calls block(@[]) [parser parse:data("}[]"]; //
next part of stream // calls block(@{}) // calls block(@[])
Compromise: “garbage after JSON” []**xx block(@[]) errorHandler(…)
–Johnny Appleseed “What if I am using a 3rd-party API
that just gives me a long list?”
Root array chunks [ [1,2,3], {“foo”:42}, [true,false] ]
Unwrap the root array! id parser = [SBJson4Parser unwrapRootArrayParserWithBlock:block errorHandler:eh];
Unwrap the root array! [parser parse:data("[[],{")]; // calls block(@[]) [parser
parse:data("},true]")]; // calls block(@{}) // calls block(@(YES))
Unwrap the root array! [parser parse:data("[[],{")]; // calls block(@[]) [parser
parse:data("},true]")]; // calls block(@{}) // calls block(@(YES))
Compromise: Corrupted / incomplete JSON [ {}, [], ***###$#”>P block(@{})
block(@[]) errorHandler(…)
Unwrapping is for root-level arrays only!
SBJson’s Blocks SBJson4ValueBlock block = ^(id obj, BOOL *stop) {
if (some_condition) { *stop = YES; } else { // do something with obj } };
SBJson4ParserStatus switch ([parser parse:data]) { case SBJson4ParserStopped: case SBJson4ParserComplete: NSLog(“Done!");
case SBJson4ParserWaitingForData: break; case SBJson4ParserError: NSLog(@"Ouch, I'm hurt!"); break; }
Use with custom NSURLSessionDataDelegate - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dt didReceiveData:(NSData
*)data { switch ([parser parse: data]) { // handle various returns here… } }
Two CocoaPods! To allow both version 3 and 4 in
the same application.
http://www.flickr.com/photos/dullhunk/202872717/