Reputation: 1924
I have a hash in the structure below
{
"Result": [
{
"Links": [
{
"UrlTo": "http://www.example.com/",
"Visited": 1365128454,
"FirstSeen": 1351907446,
}
],
"Index": 0,
"Rating": 120.969674
}
]
}
But I want it flattened and to look as it does below. So I want to move the links hash up a level so it is no longer multidimensional. What is the easiest way of accomplishing this? can i used something like .flatten?
{
"Result": [
{
"UrlTo": "http://www.example.com/",
"Visited": 1365128454,
"FirstSeen": 1351907446,
"Index": 0,
"Rating": 120.969674
}
]
}
Many thanks
Upvotes: 0
Views: 1708
Reputation: 42421
data = { ... }
h = data['Result'].first
h.merge!(h.delete('Links').first)
Upvotes: 4