ruby on rails - Hash to_json: how can I skip the key and list only the values in the JSON response? -
ruby on rails - Hash to_json: how can I skip the key and list only the values in the JSON response? -
the result of activerecord
query array of hashes. if convert json output, keys of hash (the db column names) repeated in json result every row. e.g. dailystats.all.to_json
gives back:
[ {\"statisticsdate\":1360454400000,\"storagetoptempavg\":48.6}, {\"statisticsdate\":1360540800000,\"storagetoptempavg\":49.0}, {\"statisticsdate\":1360627200000,\"storagetoptempavg\":48.4} ]
however omit column names repeated , this:
[ {1360454400000:48.6}, {1360540800000:49.0}, {1360627200000:48.4} ]
is there simple way or should build info converter?
you should able map info before convert json:
dailystats.all.map {|item| {item[:statisticsdate] => item[:storagetoptempavg]}}.to_json
ruby-on-rails ruby json rails-activerecord
Comments
Post a Comment