Created
September 7, 2023 00:31
-
-
Save mkasberg/a87f0aaa0cf1f374c11c2e0124269d2c to your computer and use it in GitHub Desktop.
Boilerplate to parse JSON in Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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