node-csvtojson
node-csvtojson copied to clipboard
Can't work out the structure to re create someone else's JSON from CSV
Hi,
I am trying to add some more JSON content to my work with the combination of someone else's JSON database of addresses but when I convert my CSV file to JSON using this great package I cannot work out how to get the same format as the original JSON data.
Here is a sample of the original data
{"address1":"1745 T Street Southeast","address2":"","city":"Washington","state":"DC","postalCode":"20020","coordinates":{"lat":38.867033,"lng":-76.979235}}
The main importance here is the coordinates being inside of another object, how can I convert my current CSV data:
lng,lat,city 22.8715715,52.358377,Kózki
To output in the same format as the original, currently, it outputs to:
{"lng":"22.8715715","lat":"52.358377","city":"Kózki"}
It seems like a small challenge but I cannot work it out, I just need to wrap those two coordinates in a "coordinates" object.
Thank you
you can use nested json structure (https://github.com/Keyang/node-csvtojson#nested-json-structure) it is important to have it defined in your head line (you can override it through headers parameters):
coordinates.lat,coordinates.lng,city
22.8715715,52.358377,Kózki
Should give you
[
{
"coordinates": {
"lat": "22.8715715",
"lng": "52.358377"
},
"city": "Kózki"
}
]
Awesome that works thank you very much, this package has been insanely helpful by the way thank you so much!
can someone upload a sample CSV file with nested values here