Skip to content

Instantly share code, notes, and snippets.

@ZenCocoon
Created January 15, 2010 08:48
Show Gist options
  • Save ZenCocoon/277910 to your computer and use it in GitHub Desktop.
Save ZenCocoon/277910 to your computer and use it in GitHub Desktop.
## JSON output naturally ordered
# Actual result
>> { :b => "b", :a => ["a", "c", "b", { :c => "c", :a => "a", :b => "b"}], :c => "c" }.to_json
=> "{\"b\":\"b\",\"c\":\"c\",\"a\":[\"a\",\"c\",\"b\",{\"b\":\"b\",\"c\":\"c\",\"a\":\"a\"}]}"
# Desired result
>> { :b => "b", :a => ["a", "c", "b", { :c => "c", :a => "a", :b => "b"}], :c => "c" }.to_json
=> "{\"a\":[\"a\",\"c\",\"b\",{\"a\":\"a\",\"b\":\"b\",\"c\":\"c\"}],\"b\":\"b\",\"c\":\"c\"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment