Recently delving into the realms of JSON and JavaScript, I found myself tasked with creating a table in Cloudant NoSQL. Upon gathering Weather data from a reliable Weather Company in JSON format to upload onto Cloudant, I encountered some irrelevant data that didn't align with the table I aimed to construct. Is there a method using JavaScript to eliminate the metadata and the column name "observation" from the received JSON data?
This is the JSON data at hand:
{
"metadata": {
"language": "en-US",
"transaction_id": "1503766402801:1454518918",
"version": "1",
"latitude": 12.83,
"longitude": 77.68,
"expire_time_gmt": 1503771300,
"status_code": 200
},
"observation": {
"key": "43295",
"class": "observation",
"expire_time_gmt": 1503771300,
"obs_id": "43295",
"obs_name": "Bangalore",
"valid_time_gmt": 1503759600,
"day_ind": "N",
"temp": 75,
"wx_icon": 29
}
}
The desired JSON structure is as follows:
{
"_id": "2e5e0da1f82157dd6f5d381a4c9ff84e",
"_rev": "1-b7a92ae5f96b051f0add3b26a14543c2",
"key": "43295",
"class": "observation",
"expire_time_gmt": 1503771300,
"obs_id": "43295",
"obs_name": "Bangalore",
"valid_time_gmt": 1503759600,
"day_ind": "N",
"temp": 75,
"wx_icon": 29
}
Thank you for any assistance.
UPDATE: While I managed to remove the metadata using "delete data.metadata;" where 'data' holds the JSON, I am still facing challenges removing the word "observation" and the curly braces towards the end.