0

I try to read json content from a file, then parse and output it:

var fs = require('fs');
var data = fs.readFileSync(filename, 'utf8');
var json = JSON.parse(data);
console.log(json);

Case 1

JSON:

{
  "css": {
    "my.css": [
      "MyFolder/MyFile.less"
    ]
  }
}

Output:

{ css: { 'my.css': [ [Circular] ] } }

Case 2

JSON:

{
  "css": {
    "my.css": [
      "MyFolder/MyFile.less",
      "MyFolder/MyOtherFile.less"
    ]
  }
}

Output:

{ css: { 'my.css': [ 'MyFolder/MyFile.less', 'MyFolder/MyOtherFile.less' ] } }

Why do I get [Circular] in Case 1?

turbophi
  • 151
  • 2
  • 8
  • may be this would do http://stackoverflow.com/questions/15312529/resolve-circular-references-from-json-object – Raja G Aug 22 '16 at 12:28
  • @Raja How does this help me? It's obvious that my json does not contain a reference, therefore a circular reference is not possible. – turbophi Aug 22 '16 at 12:33
  • FWIW, I do not get this `Circular` -- using node 6.4.0 on mac. Getting the expected result: `{ css: { 'my.css': [ 'MyFolder/MyFile.less' ] } }` – Josh Aug 22 '16 at 12:34
  • 1
    By definition `JSON.parse` would not complain about circularity, so something is going on that you're not showing us. –  Aug 22 '16 at 13:02

0 Answers0