SlideShare a Scribd company logo
BLDR
                             Minimalist JSON templating DSL

                                      Alex Sharp
                                      @ajsharp


Friday, September 30, 2011
WHO AM I?

       Alex Sharp (@ajsharp)

       Ruby Engineer at Zaarly (zaarly.com)




Friday, September 30, 2011
WHAT IS ZAARLY?

       Buyer-centric local commerce platform

       Heavily api driven (iOS, Android, Web, HTML5 mobile)

       API only speaks json




Friday, September 30, 2011
WHY BLDR?




Friday, September 30, 2011
LET ME COUNT THE REASONS

       #as_json quickly gets...unwieldy

       We need tight control over our json responses




Friday, September 30, 2011
SECURITY EXPLOIT

       We were leaking information in our json documents we
       weren’t aware of

       We didn’t understand #as_json was recursing through
       relationships and serializing them

       Not good...




Friday, September 30, 2011
TECHCRUNCH STORY




Friday, September 30, 2011
BLDR

       We wanted a simple, declarative DSL for defining JSON
       responses




Friday, September 30, 2011
BLDR

       Simple, declarative DSL

       Works with Sinatra

       Rails 3 support nearly complete

       Four DSL methods (object, collection, attribute, attributes)




Friday, September 30, 2011
SINATRA

     get '/foo' do
       bar = 'baz'
       bldr :foo, :locals => {:bar => bar}
     end




Friday, September 30, 2011
SINATRA

        # foo.bldr
        object do
          attribute :foo, bar
        end

        # output
        {"foo": "baz"}


Friday, September 30, 2011
ATTRIBUTE LISTS
           object :post => post do
             attributes :title, :body
           end

           { "post": {
               "title": "my title",
               "body": "..."
             }
           }
Friday, September 30, 2011
IMPLIED OBJECTS
           object :post do
             attributes :title, :body
           end

           { "post": {
               "title": "my title",
               "body": "..."
             }
           }
Friday, September 30, 2011
DYNAMIC ATTRIBUTES
       object :post do
         attribute :comment_count do |post|
           post.comments.count
         end
       end

       { "post": {"comment_count":1} }



Friday, September 30, 2011
OBJECT NESTING
     object :post => post do
       attributes :title, :body

       object :author => post.author do
         attribute :last_name
       end
     end

     { "post": {
         "title": "my title",
         "body": "...",
         "author": {"last_name": "Doe"}
       }
     }
Friday, September 30, 2011
ATTRIBUTE ALIASES
     object :post => post do
       attributes :title, :body

       object :author => post.author do
         attribute :surname => :last_name
       end
     end

     { "post": {
         "title": "my title",
         "body": "...",
         "author": {"surname": "Doe"}
       }
     }
Friday, September 30, 2011
TOP-LEVEL COLLECTIONS
   collection :posts => posts do
     attributes :title, :body
     attribute :comment_count { |post| post.comments.count }
   end



      { "posts": [
         { "title": "my title",
           "comment_count": 2,
         }
      ]}



Friday, September 30, 2011
NESTED COLLECTIONS
      collection :posts => posts do
        collection :comments => current_object.comments do
          attributes :body, :author, :email
        end
      end
     { "posts": [
        { "comments": [
            { "body": "...",
              "author_name": "Comment Troll",
              "email": "troll@trolling.edu" }
        ]}
     ]}


Friday, September 30, 2011
OTHER FEATURES

       Uses multi_json gem -- pick your encoding library

       Bldr.handler




Friday, September 30, 2011
Bldr.handler BSON::ObjectId do |value|
      val.to_s # => "4e77a682364141ecf5000002"
    end




Friday, September 30, 2011
MORE INFO




Friday, September 30, 2011
MORE INFO

       github.com/ajsharp/bldr

       @ajsharp

       ajsharp@gmail.com

       zaarly.com / alexjsharp.com




Friday, September 30, 2011
Ad

More Related Content

More from Alex Sharp (11)

Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSLBldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
Alex Sharp
 
Mysql to mongo
Mysql to mongoMysql to mongo
Mysql to mongo
Alex Sharp
 
Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010
Alex Sharp
 
Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010
Alex Sharp
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Alex Sharp
 
Practical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby MidwestPractical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby Midwest
Alex Sharp
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSF
Alex Sharp
 
Practical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbPractical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo Db
Alex Sharp
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
Alex Sharp
 
Getting Comfortable with BDD
Getting Comfortable with BDDGetting Comfortable with BDD
Getting Comfortable with BDD
Alex Sharp
 
Testing Has Many Purposes
Testing Has Many PurposesTesting Has Many Purposes
Testing Has Many Purposes
Alex Sharp
 
Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSLBldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
Alex Sharp
 
Mysql to mongo
Mysql to mongoMysql to mongo
Mysql to mongo
Alex Sharp
 
Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010
Alex Sharp
 
Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010
Alex Sharp
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Alex Sharp
 
Practical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby MidwestPractical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby Midwest
Alex Sharp
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSF
Alex Sharp
 
Practical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbPractical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo Db
Alex Sharp
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
Alex Sharp
 
Getting Comfortable with BDD
Getting Comfortable with BDDGetting Comfortable with BDD
Getting Comfortable with BDD
Alex Sharp
 
Testing Has Many Purposes
Testing Has Many PurposesTesting Has Many Purposes
Testing Has Many Purposes
Alex Sharp
 

Recently uploaded (20)

Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Ad

Bldr - Rubyconf 2011 Lightning Talk

  • 1. BLDR Minimalist JSON templating DSL Alex Sharp @ajsharp Friday, September 30, 2011
  • 2. WHO AM I? Alex Sharp (@ajsharp) Ruby Engineer at Zaarly (zaarly.com) Friday, September 30, 2011
  • 3. WHAT IS ZAARLY? Buyer-centric local commerce platform Heavily api driven (iOS, Android, Web, HTML5 mobile) API only speaks json Friday, September 30, 2011
  • 5. LET ME COUNT THE REASONS #as_json quickly gets...unwieldy We need tight control over our json responses Friday, September 30, 2011
  • 6. SECURITY EXPLOIT We were leaking information in our json documents we weren’t aware of We didn’t understand #as_json was recursing through relationships and serializing them Not good... Friday, September 30, 2011
  • 8. BLDR We wanted a simple, declarative DSL for defining JSON responses Friday, September 30, 2011
  • 9. BLDR Simple, declarative DSL Works with Sinatra Rails 3 support nearly complete Four DSL methods (object, collection, attribute, attributes) Friday, September 30, 2011
  • 10. SINATRA get '/foo' do bar = 'baz' bldr :foo, :locals => {:bar => bar} end Friday, September 30, 2011
  • 11. SINATRA # foo.bldr object do attribute :foo, bar end # output {"foo": "baz"} Friday, September 30, 2011
  • 12. ATTRIBUTE LISTS object :post => post do attributes :title, :body end { "post": { "title": "my title", "body": "..." } } Friday, September 30, 2011
  • 13. IMPLIED OBJECTS object :post do attributes :title, :body end { "post": { "title": "my title", "body": "..." } } Friday, September 30, 2011
  • 14. DYNAMIC ATTRIBUTES object :post do attribute :comment_count do |post| post.comments.count end end { "post": {"comment_count":1} } Friday, September 30, 2011
  • 15. OBJECT NESTING object :post => post do attributes :title, :body object :author => post.author do attribute :last_name end end { "post": { "title": "my title", "body": "...", "author": {"last_name": "Doe"} } } Friday, September 30, 2011
  • 16. ATTRIBUTE ALIASES object :post => post do attributes :title, :body object :author => post.author do attribute :surname => :last_name end end { "post": { "title": "my title", "body": "...", "author": {"surname": "Doe"} } } Friday, September 30, 2011
  • 17. TOP-LEVEL COLLECTIONS collection :posts => posts do attributes :title, :body attribute :comment_count { |post| post.comments.count } end { "posts": [ { "title": "my title", "comment_count": 2, } ]} Friday, September 30, 2011
  • 18. NESTED COLLECTIONS collection :posts => posts do collection :comments => current_object.comments do attributes :body, :author, :email end end { "posts": [ { "comments": [ { "body": "...", "author_name": "Comment Troll", "email": "[email protected]" } ]} ]} Friday, September 30, 2011
  • 19. OTHER FEATURES Uses multi_json gem -- pick your encoding library Bldr.handler Friday, September 30, 2011
  • 20. Bldr.handler BSON::ObjectId do |value| val.to_s # => "4e77a682364141ecf5000002" end Friday, September 30, 2011
  • 22. MORE INFO github.com/ajsharp/bldr @ajsharp [email protected] zaarly.com / alexjsharp.com Friday, September 30, 2011