data = [{'name':'John'},
{'name':'Smith'},
{'name':'James'}]
What is the best way to transform the array above into this format?
var name = {
"user": {
"name" : [{'name':'John'},
{'name':'Smith'},
{'name':'James'}]
}
}
I attempted to use var name['name'] = data but I am unsure how to properly wrap the result. My goal is to enclose the outcome with 'user' as it's associated.