github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

techcrunch / json_printer

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 36
    • 4
  • Source
  • Commits
  • Network (4)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Ruby JSON pretty-printer — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

patch escape_json_string to make it more UTF-8-safe 
gderosa (author)
Wed Nov 18 11:12:28 -0800 2009
commit  190489cb4c882a91fc63117712d95f759ac03dd8
tree    cb942a6116a72c6c625e65336154ec12b97e63d2
parent  f927d0e66a697170fa599dd82f1423c1bb4c3461
json_printer /
name age
history
message
file LICENSE Fri Feb 20 11:54:11 -0800 2009 Add MIT license [mmcgrana]
file README.textile Fri Feb 20 11:54:11 -0800 2009 Add MIT license [mmcgrana]
directory lib/ Wed Nov 18 11:12:28 -0800 2009 patch escape_json_string to make it more UTF-8-... [gderosa]
directory spec/ Thu Aug 28 12:18:40 -0700 2008 Add spec for new Time rendering ability [mmcgrana]
README.textile

JsonPrinter allows you to convert arbitrarily nested Ruby data structures into
human-and-machine-readable JSON output. The input data can be any combination
of arrays, hashes, symbols, strings, numbers, times, and false, true, and nil values.


  data = 
   {"attribute" => "value",
    "blank" => nil,
    "list" => 
      [true,
       2,
       "elem_number_three"],
    "nested_hash" =>
      {"key" => 7,
       "other_key" => 13.5}}
  
  JsonPrinter.render(data)
  #=>
  {"nested_hash":
   {"other_key": 13.5,
    "key": 7},
   "list":
    [true,
     2,
     "elem_number_three"],
   "blank": null,
   "attribute": "value"}

  JSON.parse(JsonPrinter.render(data)) == data
  #=> true

The printer recognizes instances of ActiveSupport::OrderedHash or other Hash-like objects responding to #keys and will render their attributes in order:


  data = 
    ActiveSupport::OrderedHash.new(
      [["foo", "bar"], ["biz", "bat"], ["cat", "hat"]])
      
  JsonPrinter.render(data)
  #=>
  {"foo": "bar",
   "biz": "bat",
   "cat", "hat"}

Copyright 2009 Mark McGranaghan and released under an MIT license.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server