I want to convert the following excel to JSON template using automation (either using any python or JS library).
The Excel Format that I have is as follows: https://docs.google.com/spreadsheets/d/1-vwP_R77dSQsAngfAHQJojd-SR6ncjLYWSpJrxpKbL4/edit?usp=sharing
The JSON output which is expected is as follows:
[
{
"Old Field Name": "PRIORITY",
"Old Field Label": "Priority",
"New Field Label": "Priority",
"New Field Name": "Priority",
"Conversion": [
{
"Method": "Mapping",
"Mapping": [
"1-high : High",
"2-medium : Medium",
"3-low : Low"
]
}
]
},
{
"Old Field Name": "REVIEWER",
"Old Field Label": "Reviewer",
"New Field Label": "Author",
"New Field Name": "Author",
"Conversion": [
{
"Method": "CONCAT",
"Conversion": "Reviewer + <REVIEWER>"
}
]
},
{
"Old Field Name": "NAME",
"Old Field Label": "Name",
"New Field Label": "Head",
"New Field Name": "Head"
}
]
Can someone suggest any steps to achieve the following conversion into the nested JSON as shown above, or any work around to automate the following scenario.
Note: I am looking forward to JS or Python Solution but I am fine with C# Libraries or any JAVA Library as well.
2
Answers
I’ve come up with the following as a standalone script:
quick note, you don’t truly need to include all those options with Papa.parse. I did so that it works exactly the same for everyone
In order to use this, you will need NodeJS and install papaparse using
npm i papaparse
.If possible, just for better scalability, you could consider using
CONCAT
orconcat
as the key instead ofConversion
, and with that in place, we could apply a general rule of "take the conversion method as the key", and thusly write:Let me know if you have any questions! 🙂
Ok here’s a solution in JS/Node.js.
First export from Google Spreadsheet as csv. (Note: If you do this in Excel the export might be slightly different, so I went from a Google Spreadsheet export).
This is the CSV I got, saved it as MigrationTool.csv
Next write JavaScript code to convert, rather tricky one this actually, but here goes:
Run the program and you’ll get this JSON in a file called MigrationTool.json:
Lastly, get paid? 😀
No, it’s fine was a fun code challenge on a Sunday. 🙂