I am working with a JSON file that looks like this:
{
"soils": [{
"mukey": "658854",
"mukeyName": "Meggett-Kenansville-Garcon-Eunola-Blanton-Bigbee (s1517)",
"sl_source": "Fl soil map",
"cokey": "3035468",
"soilName": "Eunola",
"comppct_r": 20,
"compArea": "9.96"
}],
"asfirs": [{
"long": -82.96896600817682,
"lat": 29.977675992923395
}],
"polygon": [{
"rings": [
[
[-9235836.910744485,
3501136.0564117758
],
[-9235798.692230342,
3500237.921329426
],
[-9236553.507884657,
3500667.87961353
],
[-9235836.910744485,
3501136.0564117758
]
]
],
"spatialReference": {
"wkid": 102100,
"latestWkid": 3857
}
}]
}
I need to extract the value of the Polygon key and create another JSON object like the one below:
{
"rings": [
[
[-9161396.799823288,
3453315.140590871
],
[-9160708.866568722,
3453095.3841345515
],
[-9161349.02668061,
3452751.4175072685
],
[-9161396.799823288,
3453315.140590871
]
]
],
"spatialReference": {
"wkid": 102100,
"latestWkid": 3857
}
}
However, when I try to do this using the code below, I end up with an extra set of brackets [] in the result which is causing issues:
var key3 = 'polygon';
var newPolygonJSON = polygonJson[key3];
var text = JSON.stringify(newPolygonJSON);
The output includes an unnecessary set of brackets as shown below:
[
{
"rings": [
[
[-9235836.910744485,
3501136.0564117758
],
[-9235798.692230342,
3500237.921329426
],
[-9236553.507884657,
3500667.87961353
],
[-9235836.910744485,
3501136.0564117758
]
]
],
"spatialReference": {
"wkid": 102100,
"latestWkid": 3857
}
}
]
I'm looking for a solution to remove these extra brackets and properly extract the value. Any ideas on how to achieve this?