0

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.

3
  • Questions on the main SO site need to be in English. You may find better luck with pt.stackexchange.com. Commented May 3, 2022 at 17:23
  • Hard to say without seeing the format of the log. Typically a call to JSON.stringify(some_object) is made but you'd likely need to convert the file to simple objects first Commented May 3, 2022 at 17:37
  • Does this answer your question? How to convert .txt file to JSON using React and JavaScript Commented May 5, 2022 at 16:45

1 Answer 1

0

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`);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.