Skip to content

Instantly share code, notes, and snippets.

@mkasberg
Created September 7, 2023 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkasberg/a87f0aaa0cf1f374c11c2e0124269d2c to your computer and use it in GitHub Desktop.
Save mkasberg/a87f0aaa0cf1f374c11c2e0124269d2c to your computer and use it in GitHub Desktop.
Boilerplate to parse JSON in Javascript
#!/usr/bin/env node
const fs = require('fs');
const filename = process.argv[2];
if (filename == null) {
console.log("Usage: parse_json.js FILENAME.json")
process.exit(1);
}
const fileContents = fs.readFileSync(filename, { encoding: 'utf8' });
const data = JSON.parse(fileContents);
console.log(JSON.stringify(data, null, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment