How do I convert json payload to csv, excel format on edge?
Please share any examples on github...
Requirement: APIs output format can be of: XML, Excel, CSV and JSON
If requested format is XML then proxy will return XML
Otherwise
it will return JSON payload for { CSV, Excel, Json }
Output Json = { Json }
Output CSV = { CSV structured in JSON } or direct CSV with supporting headers
Output Excel = { Excel data as base64encoded into JSON }
Example:
{ "response": "JVBERi0xLjcKJeLjz9MKNiAwIG9iago8....", "meta": { "encoding": "base64", "content-type": "application\/xls" } }
Are there any other best ways of doing the above?
hi @nagesh. You can leverage Node.js modules to manage these types of transformations. Here are some references to try:
json2csv: To transform json to CSV. https://www.npmjs.com/package/json2csv
xlsx: Excel Parser and Writer. https://www.npmjs.com/package/xlsx
fast-csv: To parse and format CSV streams. https://www.npmjs.com/package/fast-csv
You could also leverage a multiple libraries to support multiple payloads transformations. E.g. Transformation to Excel can be implemented first by transforming JSON to CSV, and then CSV to Excel format. Please try them on Edge first to ensure compatibility.