You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I read from a JSON file created by right clicking a folder and selecting add new item, the file cannot be parsed after it's contents are read.
The only JSON files I can parse are the ones that I created before starting to use Visual Studio. In the below picture, root is able to be parsed, but multipart throws the error. I know it's not the code because I replaced root by copying it's contents, deleting it, then readding root using add new item, then pasting the exact same code that worked before in it, and then it started throwing the same error as multipart.
When I do:
JSON.parse(content);
where content is the result of reading from the json file. It throws the following syntax error:
SyntaxError: Unexpected token 
I tried just printing out the content using console.log before parsing the JSON and it looks like what's happening is that a "?" is being appended in front of the files contents for some reason.
The text was updated successfully, but these errors were encountered:
The token being referenced is actually the UTF-8 BOM, and Node has decided that fs.readFile is not going to strip the BOM markers, hence the error you are seeing. There are a couple workarounds described in this StackOverflow answer, and in VS you can change the encoding of the file by File > Advanced Save Options, and selecting Unicode (UTF-8 without signature) as the encoding.
That said, I wouldn't take issue with changing the default of the json files in the "new item" dialog to avoid additional confusion.
Okay, closing this issue as external for now, and we can revisit if more people complain. I'm on the fence about changing the default as I'd prefer a potential issue like this to be visible rather than hidden.
When I read from a JSON file created by right clicking a folder and selecting add new item, the file cannot be parsed after it's contents are read.
The only JSON files I can parse are the ones that I created before starting to use Visual Studio. In the below picture, root is able to be parsed, but multipart throws the error. I know it's not the code because I replaced root by copying it's contents, deleting it, then readding root using add new item, then pasting the exact same code that worked before in it, and then it started throwing the same error as multipart.
When I do:
where content is the result of reading from the json file. It throws the following syntax error:
I tried just printing out the content using console.log before parsing the JSON and it looks like what's happening is that a "?" is being appended in front of the files contents for some reason.
The text was updated successfully, but these errors were encountered: