I have some results:
puts result
That look like this output:
Allowed
20863963
1554906
Denied
3607325
0
Quarantined
156240
0
Debug
p results
output
[["Allowed", 20863963, 1554906], ["Denied", 3607325, 0], ["Quarantined", 156194, 0]]
The headers are:
status,hits,page_views
I need to convert this to json. If the results was in standard csv format then it would be straight forward but how would one approach it if the results format looked like above?
Expected output something similar to this:
[{"status":"Allowed","hits":"20863963","page_views":"1554906"},{"status":"Denied","hits":"3607325","page_views":"0"},{"status":"Quarantined","hits":"156240","page_views":"0"}]
Solution
a = result.map{|s| {status: s[0], hits: s[1].to_i, page_views: s[2].to_i} }
puts a.to_json
resultis? An array? Can you please post the output you expect to get?