Skip to content

Instantly share code, notes, and snippets.

@pwfcurry
Created October 20, 2020 09:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwfcurry/5aaccc4a74309d04b8defbf732d7ff18 to your computer and use it in GitHub Desktop.
Save pwfcurry/5aaccc4a74309d04b8defbf732d7ff18 to your computer and use it in GitHub Desktop.
Converts Sainsbury json receipt to csv
// node <this file.js> <sainsbury json receipt>
const fs = require("fs");
const file = process.argv[2];
const data = JSON.parse(fs.readFileSync(file, { encoding: "utf8", flag: "r" }));
console.log("name,qty,total");
data.order_items.map(item => {
const name = item.product.name.replace(",", "");
const adjustment = parseFloat(item.product.totalAdjustment.value);
const total = item.sub_total + adjustment;
console.log([name, item.quantity, total].join(","));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment