SlideShare a Scribd company logo
Bldr
A minimalist JSON templating DSL
github.com/ajsharp/bldr
github.com/ajsharp/bldr
github.com/ajsharp/bldr
github.com/ajsharp/bldr
What?
• Produce JSON from ruby objects
• 4 core API methods
• Treat json API responses as a view layer concern
• Support for rack/sinatra and rails 3.2
• In production use at Zaarly for ~2 years
Bldr in a nutshell
github.com/ajsharp/bldr
Why?
• Rails is a great framework for building API services
• But #as_json is not for serving prod-ready json
• APIs are not intuitive for other json templating engines
• See: rabl, json_builder, et al
object :post => @post do
attributes :title, :body
end
{
"post":{
"title":"my title",
"body": "..."
}
}
bldr JSON
github.com/ajsharp/bldr
Example: objects
bldr JSON
collection :posts => @posts do |post|
attributes :title, :body
attribute(:created_at) {
post.created_at.iso8601
}
end
{"posts": [
{
"title": "Railsconf 2013 wrap-up",
"body": "...",
"created_at": "2013-05-01T14:18:16-07:00"
},
{
"title": "OMG Railsconf is coming up!",
"body": "...",
"created_at": "2013-04-20T08:01:12-07:00"
}
]}
github.com/ajsharp/bldr
Example: collections
bldr JSON
collection :posts => @posts do |post|
attributes :title, :body
attribute(:created_at) { post.created_at.iso8601 }
collection :comments => post.comments do |comment|
attributes(:author_name)
attribute(:body) {
HTML::Whitelister.clean(comment.body)
}
end
end
{"posts": [{
"title": "Railsconf 2013 wrap-up",
"body": "...",
"created_at": "2013-05-01T14:18:16-07:00",
"comments":[
{
"author_name": "Bob Bobberson",
"body": "ohai!"
}
]
}]
}
github.com/ajsharp/bldr
Example: nested collections
Rails Sinatra
github.com/ajsharp/bldr
class PostsController < ApplicationController
# GET /posts
def index
@posts = Post.all.limit(10)
render :index
end
end
# app/views/posts/index.json.bldr
collection :posts => @posts do |post|
# ...
end
class Api::Posts < Sinatra::Application
register Sinatra::Bldr
get '/posts' do
@posts = Post.all.limit(10)
bldr :'posts/index'
end
end
# views/posts/index.json.bldr
collection :posts => @posts do |post|
# ...
end
Example: Rails / Sinatra
twitter @ajsharp
web alexjsharp.com
github.com/ajsharp/bldr

More Related Content

What's hot (20)

PPTX
I18nize Scala programs à la gettext
Ngoc Dao
 
PPT
Rubyon Rails
Kevin Gisi
 
KEY
The Ruby Racer: under the hood
cowboyd
 
PDF
Consuming REST services with ActiveResource
Wolfram Arnold
 
PDF
Railsチュートリアルの歩き方 (第3版)
Yohei Yasukawa
 
PDF
Christmas present for you
Kazuki Tanaka
 
PPTX
Hands on Gradle
Mushfekur Rahman
 
PPTX
Declarative JavaScript concepts and implemetation
Om Shankar
 
PDF
GraphQL over REST
Bongwon Lee
 
PPTX
Webservices: The RESTful Approach
Mushfekur Rahman
 
PPTX
Intro to Clojure lightningtalk
Nola Stowe
 
PDF
Letswift18 키노트
Jung Kim
 
PPTX
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
PDF
How to Begin to Develop Ruby Core
Hiroshi SHIBATA
 
PPTX
Intro to Clojure 4 Developers
Nola Stowe
 
PPTX
Oak, the architecture of Apache Jackrabbit 3
Jukka Zitting
 
PDF
Bhavesh ro r
bhavesh-gloscon
 
PDF
Ruby on Rails Presentation
Joost Hietbrink
 
I18nize Scala programs à la gettext
Ngoc Dao
 
Rubyon Rails
Kevin Gisi
 
The Ruby Racer: under the hood
cowboyd
 
Consuming REST services with ActiveResource
Wolfram Arnold
 
Railsチュートリアルの歩き方 (第3版)
Yohei Yasukawa
 
Christmas present for you
Kazuki Tanaka
 
Hands on Gradle
Mushfekur Rahman
 
Declarative JavaScript concepts and implemetation
Om Shankar
 
GraphQL over REST
Bongwon Lee
 
Webservices: The RESTful Approach
Mushfekur Rahman
 
Intro to Clojure lightningtalk
Nola Stowe
 
Letswift18 키노트
Jung Kim
 
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
How to Begin to Develop Ruby Core
Hiroshi SHIBATA
 
Intro to Clojure 4 Developers
Nola Stowe
 
Oak, the architecture of Apache Jackrabbit 3
Jukka Zitting
 
Bhavesh ro r
bhavesh-gloscon
 
Ruby on Rails Presentation
Joost Hietbrink
 

Viewers also liked (9)

PPTX
Validation of Derived Features and Well-Formedness Constraints in DSLs
Daniel Varro
 
PPT
Internal DSLs For Automated Functional Testing
John Sonmez
 
PPTX
Инструментарий для создания дистрибутивов продуктов | Владимир Селин
Positive Hack Days
 
PPTX
DSL in test automation
test test
 
PDF
20 examples on Domain-Specific Modeling Languages
Juha-Pekka Tolvanen
 
PDF
Fantastic DSL in Python
kwatch
 
PPTX
Domain-Specific Languages
Javier Canovas
 
PDF
Лучшие практики Continuous Delivery с Docker / Дмитрий Столяров (Флант)
Ontico
 
PDF
Creating Domain Specific Languages in Python
Siddhi
 
Validation of Derived Features and Well-Formedness Constraints in DSLs
Daniel Varro
 
Internal DSLs For Automated Functional Testing
John Sonmez
 
Инструментарий для создания дистрибутивов продуктов | Владимир Селин
Positive Hack Days
 
DSL in test automation
test test
 
20 examples on Domain-Specific Modeling Languages
Juha-Pekka Tolvanen
 
Fantastic DSL in Python
kwatch
 
Domain-Specific Languages
Javier Canovas
 
Лучшие практики Continuous Delivery с Docker / Дмитрий Столяров (Флант)
Ontico
 
Creating Domain Specific Languages in Python
Siddhi
 
Ad

Similar to Bldr: A Minimalist JSON Templating DSL (20)

PDF
Elasticsearch And Ruby [RuPy2012]
Karel Minarik
 
PDF
JSON API Specificiation
Wojciech Langiewicz
 
PPTX
Build JSON and XML using RABL gem
Nascenia IT
 
PDF
Introduction to Rails - presented by Arman Ortega
arman o
 
PDF
How DSL works on Ruby
Hiroshi SHIBATA
 
PPTX
Learning to code for startup mvp session 3
Henry S
 
PPTX
Rubyonrails 120409061835-phpapp02
sagaroceanic11
 
PPTX
JSON-LD update DC 2017
Gregg Kellogg
 
PDF
Creating applications with Grails, Angular JS and Spring Security
Alvaro Sanchez-Mariscal
 
PDF
GraphQL in an Age of REST
Yos Riady
 
KEY
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
Matt Gauger
 
PDF
What’s New in Rails 5.0?
Unboxed
 
PDF
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
Ruby Meditation
 
PDF
Drupal, JSON:API, and Cheap Canned Beer - Drupalcamp Atlanta 2019
Paul McKibben
 
PDF
Apache Calcite (a tutorial given at BOSS '21)
Julian Hyde
 
PDF
Change RelationalDB to GraphDB with OrientDB
Apaichon Punopas
 
PPT
Introduction to Ruby on Rails
Manoj Kumar
 
KEY
Wider than rails
Alexey Nayden
 
PPT
Gwt and rpc use 2007 1
Sam Muhanguzi
 
PPTX
Json and Jsonpath in Postgres 12
EDB
 
Elasticsearch And Ruby [RuPy2012]
Karel Minarik
 
JSON API Specificiation
Wojciech Langiewicz
 
Build JSON and XML using RABL gem
Nascenia IT
 
Introduction to Rails - presented by Arman Ortega
arman o
 
How DSL works on Ruby
Hiroshi SHIBATA
 
Learning to code for startup mvp session 3
Henry S
 
Rubyonrails 120409061835-phpapp02
sagaroceanic11
 
JSON-LD update DC 2017
Gregg Kellogg
 
Creating applications with Grails, Angular JS and Spring Security
Alvaro Sanchez-Mariscal
 
GraphQL in an Age of REST
Yos Riady
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
Matt Gauger
 
What’s New in Rails 5.0?
Unboxed
 
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
Ruby Meditation
 
Drupal, JSON:API, and Cheap Canned Beer - Drupalcamp Atlanta 2019
Paul McKibben
 
Apache Calcite (a tutorial given at BOSS '21)
Julian Hyde
 
Change RelationalDB to GraphDB with OrientDB
Apaichon Punopas
 
Introduction to Ruby on Rails
Manoj Kumar
 
Wider than rails
Alexey Nayden
 
Gwt and rpc use 2007 1
Sam Muhanguzi
 
Json and Jsonpath in Postgres 12
EDB
 
Ad

More from Alex Sharp (11)

PDF
Bldr - Rubyconf 2011 Lightning Talk
Alex Sharp
 
PDF
Mysql to mongo
Alex Sharp
 
PDF
Refactoring in Practice - Sunnyconf 2010
Alex Sharp
 
PDF
Refactoring in Practice - Ruby Hoedown 2010
Alex Sharp
 
PDF
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Alex Sharp
 
PDF
Practical Ruby Projects with MongoDB - Ruby Midwest
Alex Sharp
 
KEY
Practical Ruby Projects with MongoDB - MongoSF
Alex Sharp
 
KEY
Practical Ruby Projects With Mongo Db
Alex Sharp
 
PDF
Intro To MongoDB
Alex Sharp
 
KEY
Getting Comfortable with BDD
Alex Sharp
 
KEY
Testing Has Many Purposes
Alex Sharp
 
Bldr - Rubyconf 2011 Lightning Talk
Alex Sharp
 
Mysql to mongo
Alex Sharp
 
Refactoring in Practice - Sunnyconf 2010
Alex Sharp
 
Refactoring in Practice - Ruby Hoedown 2010
Alex Sharp
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Alex Sharp
 
Practical Ruby Projects with MongoDB - Ruby Midwest
Alex Sharp
 
Practical Ruby Projects with MongoDB - MongoSF
Alex Sharp
 
Practical Ruby Projects With Mongo Db
Alex Sharp
 
Intro To MongoDB
Alex Sharp
 
Getting Comfortable with BDD
Alex Sharp
 
Testing Has Many Purposes
Alex Sharp
 

Recently uploaded (20)

PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 

Bldr: A Minimalist JSON Templating DSL

  • 1. Bldr A minimalist JSON templating DSL github.com/ajsharp/bldr
  • 3. github.com/ajsharp/bldr What? • Produce JSON from ruby objects • 4 core API methods • Treat json API responses as a view layer concern • Support for rack/sinatra and rails 3.2 • In production use at Zaarly for ~2 years Bldr in a nutshell
  • 4. github.com/ajsharp/bldr Why? • Rails is a great framework for building API services • But #as_json is not for serving prod-ready json • APIs are not intuitive for other json templating engines • See: rabl, json_builder, et al
  • 5. object :post => @post do attributes :title, :body end { "post":{ "title":"my title", "body": "..." } } bldr JSON github.com/ajsharp/bldr Example: objects
  • 6. bldr JSON collection :posts => @posts do |post| attributes :title, :body attribute(:created_at) { post.created_at.iso8601 } end {"posts": [ { "title": "Railsconf 2013 wrap-up", "body": "...", "created_at": "2013-05-01T14:18:16-07:00" }, { "title": "OMG Railsconf is coming up!", "body": "...", "created_at": "2013-04-20T08:01:12-07:00" } ]} github.com/ajsharp/bldr Example: collections
  • 7. bldr JSON collection :posts => @posts do |post| attributes :title, :body attribute(:created_at) { post.created_at.iso8601 } collection :comments => post.comments do |comment| attributes(:author_name) attribute(:body) { HTML::Whitelister.clean(comment.body) } end end {"posts": [{ "title": "Railsconf 2013 wrap-up", "body": "...", "created_at": "2013-05-01T14:18:16-07:00", "comments":[ { "author_name": "Bob Bobberson", "body": "ohai!" } ] }] } github.com/ajsharp/bldr Example: nested collections
  • 8. Rails Sinatra github.com/ajsharp/bldr class PostsController < ApplicationController # GET /posts def index @posts = Post.all.limit(10) render :index end end # app/views/posts/index.json.bldr collection :posts => @posts do |post| # ... end class Api::Posts < Sinatra::Application register Sinatra::Bldr get '/posts' do @posts = Post.all.limit(10) bldr :'posts/index' end end # views/posts/index.json.bldr collection :posts => @posts do |post| # ... end Example: Rails / Sinatra