'How can I convert a LOG .txt to .json using JavaScript?
I'd like to know how can i convert a log to .Json using JS. Reading the data in the LOG and converting it to .json, i searched a lot and didnt find anything about it.
Solution 1:[1]
You can simply read from the .txt file then write the contents to a .json file using JSON.stringify to make sure characters such as newlines and double quotes are escaped properly.
For example using Node.js:
const fs = require('fs');
const contents = fs.readFileSync('log.txt', 'utf8');
fs.writeFileSync('log.json', `{ "data": ${JSON.stringify(contents)} }\n`);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MikeM |
