Let's say you saved the output of a PayPal NVP API request to output.txt
.
To parse it to JSON:
yarn start output.txt
An output.txt.json
will be created.
Let's say you saved the output of a PayPal NVP API request to output.txt
.
To parse it to JSON:
yarn start output.txt
An output.txt.json
will be created.
let fs = require('fs'); | |
let path = require('path'); | |
let parse = require('paypal-nvp-parser'); | |
// Make sure we got a filename on the command line. | |
if (process.argv.length < 3) { | |
console.log('Usage: node ' + process.argv[1] + ' FILENAME'); | |
process.exit(1); | |
} | |
function parsePayPal(filename) { | |
fs.readFile(filename, 'utf8', function(err, raw_paypal) { | |
if (err) throw err; | |
let parsed_paypal = parse(raw_paypal); | |
console.log(parsed_paypal); | |
writeParsedPayPal(parsed_paypal); | |
}); | |
} | |
function writeParsedPayPal(parsed_paypal) { | |
fs.writeFile(path.join(process.cwd(), `${filename}.json`), JSON.stringify(parsed_paypal, null, 2), function(err) { | |
if(err) throw err; | |
console.log(`==> Saved as: ${filename}.json`); | |
}); | |
} | |
// Read the file and print its contents. | |
let filename = process.argv[2]; | |
parsePayPal(filename); |
{ | |
"name": "parse-paypal-nvp", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"scripts": { | |
"start": "node index.js" | |
}, | |
"dependencies": { | |
"paypal-nvp-parser": "^1.0.2" | |
} | |
} |