T
T
theTeither2019-06-13 23:23:10
JavaScript
theTeither, 2019-06-13 23:23:10

What is the error when accessing the JSON file?

Good afternoon!
When requesting a JSON file, the console gives an error:

SyntaxError: Unexpected token  in JSON at position 0

var fs = require("fs");
fs.readFile("text.json",  function(err, data) {
  if (err) throw err;
  var arr = data.toString();
  arr = JSON.parse(arr);
  console.log(arr.title);
});

JSON:
{
    "title": "Закрыть",
    "action": "CloseDoc"
}

Also, the question is: is it possible to track errors when working with node using a debugger?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question