2

Whenever i am clicking on Run and Debug in vs code getting this error.

"Failed to parse json file, possibly due to comments or trailing commas."

how can i solve this?

I tried deleting the .vscode folder and doing it again but still getting this error

yugsolanki
  • 35
  • 2
  • Don't understand the downvote. I got the very same problem. There's really not much more to it. You hit F5 and get this error. At least as long as any source code window is open (which doesn't have to contain any JSON, for me it's cpp or hpp files). When I close all source code windows and hit F5 debugging starts normally. – DrP3pp3r May 24 '23 at 06:08

1 Answers1

2

I had the very same problem working on a C++ project. As soon as a source code file was open (e.g. a cpp or hpp file) hitting F5 would result in the pop-up saying

Failed to parse json file, possibly due to comments or trailing commas.

and debugging wouldn't start.

If all source code files were closed, hitting F5 started debugging as intended.

The problem for me was that my tasks.json file contained a long shell command which was using backslashes to spread it over multiple lines. Even though the command surprisingly worked it seemed to trip a JSON parser in one spot. Once I fixed the command F5 worked like a charm again.

Extra info: The message seems to come from here: https://github.com/microsoft/vscode-cpptools/blob/main/Extension/src/common.ts (microsoft/vscode-cpptools).

DrP3pp3r
  • 803
  • 9
  • 33