So, I'm working on pulling data from the https://www.aviationweather.gov/dataserver and storing it in a mongoDB. The API returns XML, and using the xml2js module for node I can convert it fairly easily to JSON and store it in a mongodb. However, the xml2js module is not 100% perfect in it's conversion, and I would like to modify some of the output after the fact, but I am not sure where to start. I was hoping someone can give me a nudge in the right direction.
Here is the current JSON output from the xml2js conversion. I've trimmed it for just the relevant parts...let me know if you need the whole thing:
With one result, it looks like this:
"sky_condition": {
"$": {
"sky_cover": "OVC",
"cloud_base_ft_agl": "1600"
}
With multiple results, it looks like this (could be a max of 4 results):
"sky_condition": [{
"$": {
"sky_cover": "BKN",
"cloud_base_ft_agl": "1800"
}
}, {
"$": {
"sky_cover": "OVC",
"cloud_base_ft_agl": "4100"
}
}]
I am hopeful that there is a way that it could be made to look like this (and up to 4 possible "cloud layers":
"sky_condition": [
{
"sky_cover": "OVC",
"cloud_base_ft_agl": "1600"
}
],
I hope this is clear, and I really appreciate any help that is tossed my way.