Skip to content

Instantly share code, notes, and snippets.

Created June 5, 2014 12:47
Show Gist options
  • Save anonymous/767a976fa54761af4400 to your computer and use it in GitHub Desktop.
Save anonymous/767a976fa54761af4400 to your computer and use it in GitHub Desktop.
rubyのシンボルを含むデータ構造をJSONに変換するとシンボルがただの文字列になる
{
"net": {
"hostname": "dqneo.example.com"
},
"users": [
{
"name": "dqneo",
"password": "himitsu"
}
],
"tz": "Asia/Tokyo"
}
#!/usr/bin/env ruby
require 'json'
data = {
:net => {
:hostname => "dqneo.example.com"
},
:users => [
{ :name => 'dqneo', :password => 'himitsu' },
],
:tz => "Asia/Tokyo",
}
puts JSON.pretty_generate(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment