Skip to content

Instantly share code, notes, and snippets.

@szydan
Created March 6, 2023 19:18
Show Gist options
  • Save szydan/b6ad9729fab246893b4769d9612cae85 to your computer and use it in GitHub Desktop.
Save szydan/b6ad9729fab246893b4769d9612cae85 to your computer and use it in GitHub Desktop.
json formatted to lines
const fs = require("fs");
const inPath = process.argv[2];
const outPath = process.argv[3];
const content = fs.readFileSync(inPath);
const json = JSON.parse(content);
const hits = json.hits.hits;
const res = [];
for (const hit of hits) {
res.push(JSON.stringify(hit));
}
const out = res.join("\n");
fs.writeFileSync(outPath, res.join("\n"));
====================
const fs = require("fs");
const inPath = process.argv[2];
const outPath = process.argv[3];
const content = fs.readFileSync(inPath);
const json = JSON.parse(content);
fs.writeFileSync(outPath, JSON.stringify(json));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment