Consider the file below being used as input for the accompanying JavaScript used in node.js. The script will fail with "Unexpected token h"
because hello
is not in quotes. Is there a way to parse this file anyway without having to fix the string first?
data.json
{
"foo": "bar",
hello: "world",
"jane": "fonda",
jimmy: "buffet"
}
index.js
/*jslint node:true*/
"use strict";
var fs = require("fs");
fs.readFile("./data.json", "utf8", function (err, data) {
var jsonData = JSON.parse(data);
console.log(jsonData);
});