I'm attempting to parse a csv file as JSON, which I have done, and it's working fine.
I now need to rename the 'product_code' key throughout the JSON to 'value', and also duplicate it (renaming the second iteration 'label'). The value will remain the same for both. I cannot edit the csv file, and this needs to be done in JavaScript / jQuery.
Hopefully this will explain it more clearly:
Existing:
{
"brand":"BrandName1",
"product_code":"001",
"product_name":"White Picture Frame",
"product_barcode":"1009842098"
},
{
"brand":"BrandName2",
"product_code":"002",
"product_name":"Yellow Picture Frame",
"product_barcode":"0982149872"
}
And I wish to change this to:
{
"brand":"BrandName1",
"value":"001",
"label":"001",
"product_name":"White Picture Frame",
"product_barcode":"1009842098"
},
{
"brand":"BrandName2",
"value":"002",
"label":"002",
"product_name":"Yellow Picture Frame",
"product_barcode":"0982149872"
}
This is so it can be used with jQuery Autocomplete.
Any help much appreciated! I'm a newbie when it comes to JSON.