JSON formatter outputs invalid JSON object due to "\n" in source property
See original GitHub issueTell 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:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?
Closing, as this doesn’t appear to be an issue with ESLint.