سؤال

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

هل كانت مفيدة؟

المحلول

data = { ... }

h = data['Result'].first
h.merge!(h.delete('Links').first)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top