I have a JSON that looks like this:
[{
"1": [{
"lat": " -1.854029",
"lng": " 36.488604"
}, {
"lat": " -1.519856",
"lng": " 36.102752"
}, {
"lat": " -1.283394",
"lng": " 36.657745"
}]
}, {
"2": [{
"lat": " -1.325416",
"lng": " 36.669051"
}, {
"lat": " -1.392932",
"lng": " 36.768752"
}, {
"lat": " -1.390505",
"lng": " 36.810023"
}, {
"lat": " -1.448266",
"lng": " 36.952769"
}, {
"lat": " -1.267033",
"lng": " 37.094882"
}, {
"lat": " -1.214605",
"lng": " 37.053978"
}, {
"lat": " -1.169516",
"lng": " 36.895608"
}]
}]
I want to convert it to this format.
{
"1": [{
"lat": " -1.854029",
"lng": " 36.488604"
}, {
"lat": " -1.519856",
"lng": " 36.102752"
}, {
"lat": " -1.283394",
"lng": " 36.657745"
}],
"2": [{
"lat": " -1.325416",
"lng": " 36.669051"
}, {
"lat": " -1.392932",
"lng": " 36.768752"
}, {
"lat": " -1.390505",
"lng": " 36.810023"
}, {
"lat": " -1.448266",
"lng": " 36.952769"
}, {
"lat": " -1.267033",
"lng": " 37.094882"
}, {
"lat": " -1.214605",
"lng": " 37.053978"
}, {
"lat": " -1.169516",
"lng": " 36.895608"
}]
}
I have tried JSON.parse(var)
but it does not give the required output. If I try to access a value in my json, it gives undefined. Please someone help no what am doing wrong. Is it the wat am creating the json? If so how should I create it so I get the required output as mentioned above. Or is the problem with the way am parsing the json?