I have a lengthy list of one-level JSON data similar to the example below: json-old.json
[
{"stock": "abc", "volume": "45434", "price": "31", "date": "10/12/12"},
{"stock": "abc", "volume": "45435", "price": "30", "date": "10/13/12"},
{"stock": "xyz", "volume": "34465", "price": "14", "date": "10/12/12"},
{"stock": "xyz", "volume": "34434", "price": "14", "date": "10/13/12"},
{"stock": "zzz", "volume": "76755", "price": "65", "date": "10/12/12"},
{"stock": "zzz", "volume": "85646", "price": "67", "date": "10/13/12"}
]
I am looking for a way to transform this file into a new format in another file: json-new.json
[
{
"abc": {
"10/12/12": { "volume": "45434", "price": "31" },
"10/13/12": { "volume": "45435", "price": "30" }
}
},
{
"xyz": {
"10/12/12": { "volume": "34465", "price": "14" },
"10/13/12": { "volume": "34434", "price": "14" }
}
},
{
"zzz": {
"10/12/12": { "volume": "76755", "price": "65" },
"10/13/12": { "volume": "85646", "price": "67" }
}
}
]
Essentially, I want to restructure and nest the data based on the 'stock' and 'date' properties.
Are there any libraries available in JavaScript or Node.js that can assist with automating this conversion process? I have numerous files in a folder that need to be transformed into a single file with the desired structure (to facilitate uploading to a database like Firebase).