question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON formatter outputs invalid JSON object due to "\n" in source property

See original GitHub issue

Tell us about your environment

  • ESLint Version: v3.8.1
  • Node Version: v5.10.1
  • npm Version: 3.10.9

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration: eslint --no-eslintrc --rule 'comma-dangle:[error,always-multiline]' --format json

What did you do? Please include the actual source code causing the issue.

var foo = {
  bar: "baz",
  qux: "quux"
};

What did you expect to happen? The returned object t be a valid JSON object.

What actually happened? Please include the actual, raw output from ESLint. The source property of the JSON object contains literal \n characters which are not valid in a JSON property value. It must be double-escaped (\\n) to be valid. Invalid output:

[{"filePath":"D:\\workspace\\work\\test.js","messages":[{"ruleId":"comma-dangle","severity":2,"message":"Missing trailing comma.","line":3,"column":14,"nodeType":"Property","source":"  qux: \"quux\"","fix":{"range":[39,39],"text":","}}],"errorCount":1,"warningCount":0,"source":"var foo = {\n  bar: \"baz\",\n  qux: \"quux\"\n};\n"}]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Nov 2, 2016

I’m a little confused by this report. The JSON you are showing seems to be valid (you are showing unquoted JSON, so I would expect \n to be interpreted as a backslash-n rather than an actual newline.

@vitorbal also took a look and fed your JSON through a validator, and it says it’s valid.

How are you using the JSON? I’m wondering if whatever tool you are feeding the JSON incorrectly into a tool, or maybe the tool has a bug deserializing the JSON?

0reactions
nzakascommented, Nov 3, 2016

Closing, as this doesn’t appear to be an issue with ESLint.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Most efficient way to fix an invalid JSON - Stack Overflow
Please remember that the string (or rather object) you've got isn't valid JSON and can't be parsed with a JSON library. It needs...
Read more >
How to allow some kinds of invalid JSON with System.Text.Json
Learn how to allow comments, trailing commas, and quoted numbers while serializing to and deserializing from JSON in .NET.
Read more >
What Is JSON and How to Handle an “Unexpected Token” Error
The first thing to do in this situation is to confirm where the error is happening exactly. To ensure the error happens on...
Read more >
I've received an "Invalid JSON string" error. What do I do?
An invalid JSON error can occur for many reasons. The most common issue is usually associated with a file upload attempt, and can...
Read more >
Working with JSON - Learn web development | MDN
JSON is purely a string with a specified data format — it contains only properties, no methods. JSON requires double quotes to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found