I'm learning JS and I have a challenge on my work but I have been spending a lot of time without get the correct structure on this JSON. So this is my problem:
The main JSON comes like:
{
"Museum_Name":"Anchorage Museum",
"Street_Address":"625 C St.",
"City":"Anchorage",
"State":"AK",
"Full_State_Name":"Arkansas",
"Zip_Code":99577,
"Phone":"907-929-9201",
"Website":"link",
"Hours":"October to April: Sat 10 a.m. to 6 p.m.; May to September: Sat 9 a.m. to 6 p.m.",
"Provided_Description":"The Anchorage Museum is the largest museum in Alaska and one of the top 10 most visited attractions in the state. The museum’s mission is to share and connect Alaska with the world through art, history and science. Located in the heart of downtown Anchorage, the museum’s collection and exhibitions tell the story of Alaska’s past, present and future. Visitor favorites include Alaska Native artifacts, Alaska art and history galleries, a planetarium and a hands-on science center for families.",
"Special_Note":"(No Sundays)",
"Latitude_Longitude":"61.215906,-149.884839"
}
Repeating the same structure with a lot of cities, states and museums, I used the following linq code:
var query = $.Enumerable.From(data)
.GroupBy(
"{ Id: $.Full_State_Name}",
"{ City_Name: $.City, Museum_Name: $.Museum_Name, link: $.Website}",
"{ State: $.Id, Cities: $$.ToArray() }",
"String($.Id) + $.City_Name + $.Website "
)
.ToJSON();
To get this new JSON:
[
{
"State": "California",
"Cities": [
{
"City_Name": "Long Beach",
"Museum_Name": "Museum of Latin American Art",
"link": "link"
},
{
"City_Name": "Los Angeles",
"Museum_Name": "Skirball Cultural Center",
"link": "link"
},
{
"City_Name": "Los Angeles",
"Museum_Name": "\nAutry National Center",
"link": "link"
}
]
}
]
And i need following structure but I don't know how to get it:
{
"State": "California",
"City": [
{
"City_Name": "Long Beach",
"Museums": [
{
"Museum_Name": "Museum of Latin American Art",
"link": "link"
}
]
},
{
"City_Name": "Los Angeles",
"Museums": [
{
"Museum_Name": "Skirball Cultural Center",
"link": "link"
},
{
"Museum_Name": "Autry National Center",
"link": "link"
}
]
}
]
}
I really appreciate any help