README.md in json_builder-3.0.7 vs README.md in json_builder-3.1.0

- old
+ new

@@ -6,28 +6,28 @@ ```ruby require 'json_builder' json = JSONBuilder::Compiler.generate do - name "Garrett Bjerkhoel" - email "spam@garrettbjerkhoel.com" + name 'Garrett Bjerkhoel' + email 'spam@garrettbjerkhoel.com' url root_path address do - street "1234 1st Ave" - street2 "Apt 1" - city "New York" - state "NY" + street '1234 1st Ave' + street2 'Apt 1' + city 'New York' + state 'NY' zip 10065 end - key :nil, "testing a custom key name" + key :nil, 'testing a custom key name' skills do ruby true asp false end longstring do # Could be a highly intensive process that only returns a string - "12345" * 25 + '12345' * 25 end end ``` Which will generate: @@ -54,11 +54,11 @@ ``` If you'd like to just generate an array: ```ruby -array ["Garrett Bjerkhoel", "John Doe"] do |name| +array ['Garrett Bjerkhoel', 'John Doe'] do |name| first, last = name.split(' ') first first last last end ``` @@ -98,17 +98,17 @@ respond_with @users end end ``` -Lastly, create `app/views/users/index.json_builder` which could look something like: +Lastly, create `app/views/users/index.json.json_builder` which could look something like: ```ruby count @users.count -current_page @users.current_page +page @users.current_page per_page @users.per_page -num_pages @users.num_pages +pages_count @users.num_pages results @users do |user| id user.id name user.name body user.body url user_url(user) @@ -122,14 +122,14 @@ You will get something like: ```json { - "total": 10, + "count": 10, "page": 1, "per_page": 2, - "total_pages": 5, + "pages_count": 5, "results": [ { "id": 1, "name": "Garrett Bjerkhoel", "body": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod.", @@ -168,11 +168,11 @@ } ``` ### Including JSONP callbacks -Out of the box JSON Builder supports JSONP callbacks when used within a Rails project just by using the callback parameter. For instance, if you requested `/users.json?callback=myjscallback`, you'll get a callback wrapping the response: +Out of the box JSON Builder supports JSONP callbacks when used within a Rails project just by using the `callback` parameter. For instance, if you requested `/users.json?callback=myjscallback`, you'll get a callback wrapping the response: ```json myjscallback([ { "name": "Garrett Bjerkhoel" @@ -181,29 +181,30 @@ "name": "John Doe" } ]) ``` -To be able to turn off this functionality, you can do it per-environment, or globally: +To turn off JSONP callbacks globally or just per-environment: -#### Per Environment +#### Globally + ```ruby -Spyder::Application.configure do - config.action_view.json_callback = false -end +ActionView::Base.json_callback = false ``` -#### Globally +#### Per Environment ```ruby -ActionView::Base.json_callback = false +Sample::Application.configure do + config.action_view.json_callback = false +end ``` ### Pretty Print Output -Out of the box JSON Builder supports pretty printing the JSON for the development environment, the rest have it turned off for performance reasons. If you'd like to enable or disable pretty printing you can do it within your environment file or you can do it globally. +Out of the box JSON Builder supports pretty printing only during development, it's disabled by default in other environments for performance. If you'd like to enable or disable pretty printing you can do it within your environment file or you can do it globally. With pretty print on: ```json { @@ -219,11 +220,11 @@ ``` #### Per Environment ```ruby -Spyder::Application.configure do +Sample::Application.configure do config.action_view.pretty_print_json = false end ``` #### Globally @@ -237,12 +238,12 @@ user system total real JSONBuilder 2.950000 0.010000 2.960000 (2.968790) Builder 10.820000 0.040000 10.860000 (10.930497) -## Other JSON Builders +## Alternative libraries -There are quite a few other alternatives to JSON Builder, each good in their own way with different DSL's and design approaches that are worth checking out: +There are alternatives to JSON Builder, each good in their own way with different API's and design approaches that are worth checking out. Although, I would love to hear why JSON Builder didn't fit your needs, by [message or issue. * [jbuilder](https://github.com/rails/jbuilder) * [RABL](https://github.com/nesquena/rabl) * [Tequila](https://github.com/inem/tequila) * [Argonaut](https://github.com/jbr/argonaut) \ No newline at end of file