Skip to content

Commit

Permalink
updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
dewski committed Aug 27, 2010
1 parent 1d9905a commit c3a45c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions README.md
@@ -1,15 +1,15 @@
# JSON Builder
Rails provides an excellent XML Builder by default to build RSS and ATOM feeds, but nothing to help you build JSON. The standard `to_json` works well, but can get very verbose when you need full control of what the user gets, this is where JSON Builder comes in.
Rails provides an excellent XML Builder by default to build RSS and ATOM feeds, but nothing to help you build complex and custom JSON data structures. The standard `to_json` works well, but can get very verbose when you need full control of what the user gets, this is where JSON Builder comes in alongside the default XML Builder.

## Using JSON Builder With Rails
Make sure to add `json_builder` to your `Gemfile`.

gem 'json_builder'

You then have the option to run your JSON through a prettifier before it's returned.
If you'd like to run the generated JSON through a prettifier for debugging reasons, just edit it in your environment config

JSON::Application.configure do
config.action_view.pretty_print_true = false
Your::Application.configure do
config.action_view.pretty_print_json = true
end

## Sample Usage
Expand All @@ -30,11 +30,11 @@ You then have the option to run your JSON through a prettifier before it's retur
json.asp false
end

puts json.compile
puts json.compile!

## Examples
See the examples directory.
http://github.com/dewski/json_builder/tree/master/examples

## Copyright
Copyright © 2010 Garrett Bjerkhoel. See MIT-LICENSE for details.
Copyright © 2010 Garrett Bjerkhoel. See [MIT-LICENSE](http://github.com/dewski/json_builder/blob/master/MIT-LICENSE) for details.
4 changes: 2 additions & 2 deletions lib/json_builder/generator.rb
Expand Up @@ -55,7 +55,7 @@ def compile!
if @is_array
compiled = ('[{' + @compiled.join(',') + '}]').gsub(',},{,', '},{')
else
compiled = '{' + @compiled.join(',') + '}'
compiled = '{' + @compiled.join(', ') + '}'
end

if @pretty_print
Expand All @@ -69,7 +69,7 @@ def compile!
private
def type_cast(text)
case text
when Array then '['+ text.map! { |j| type_cast(j) }.join(',') +']'
when Array then '['+ text.map! { |j| type_cast(j) }.join(', ') +']'
when Hash then 'teheh'
when String then "\"#{text}\""
when TrueClass then 'true'
Expand Down

0 comments on commit c3a45c8

Please sign in to comment.