Question

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

Was it helpful?

Solution

data = { ... }

h = data['Result'].first
h.merge!(h.delete('Links').first)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top