Invalid JSON character when running ng serve
Asked Answered
G

8

17

I am getting following error when running ng serve...

PS F:\Projects\RecipeApp> ng serve
Invalid JSON character: "\"" at 76:13.
Error: Invalid JSON character: "\"" at 76:13.
    at _token (F:\Projects\RecipeApp\node_modules\@angular-devkit\core\src\json\parser.js:63:19)
    at _readArray (F:\Projects\RecipeApp\node_modules\@angular-devkit\core\src\json\parser.js:316:9)
    at _readValue (F:\Projects\RecipeApp\node_modules\@angular-devkit\core\src\json\parser.js:561:22)
    at _readProperty (F:\Projects\RecipeApp\node_modules\@angular-devkit\core\src\json\parser.js:398:19)
    at _readObject (F:\Projects\RecipeApp\node_modules\@angular-devkit\core\src\json\parser.js:431:30)
    at _readValue (F:\Projects\RecipeApp\node_modules\@angular-devkit\core\src\json\parser.js:564:22)
    at _readProperty (F:\Projects\RecipeApp\node_modules\@angular-devkit\core\src\json\parser.js:398:19)
    at _readObject (F:\Projects\RecipeApp\node_modules\@angular-devkit\core\src\json\parser.js:431:30)
    at _readValue (F:\Projects\RecipeApp\node_modules\@angular-devkit\core\src\json\parser.js:564:22)
    at _readProperty (F:\Projects\RecipeApp\node_modules\@angular-devkit\core\src\json\parser.js:398:19)

I am using angular version 6

Glairy answered 25/7, 2018 at 10:48 Comment(4)
Do you have a full stack trace?Extrajudicial
Remove node_module folder , run npm install again.Broderickbrodeur
please post your error as text, not as an image.Lanthanum
I experienced the same problem. It happened after git merge which makes conflict. Just check your angular.json file.Shifrah
M
41

Check your Angular.json.

It seems that this config file is not correct.


Update for clarification:
A misplaced "/" in the angular.json will create exactly that kind of error.

Myself answered 25/7, 2018 at 10:51 Comment(4)
You'r Answer could be comment.Broderickbrodeur
In this case it´s the answer, because you will get exactly the described error, if you put a "/" at the wrong place in your Angular.json. But, yes, you are right, this could also be a comment to clarify the error description.Myself
There was syntax error in my angular.json. I'd added a line to the 'styles' section, but forgot to add a "," on the end of the previous line.Hydatid
In my case, a comma was missing from the end of a line in angular.json.Clericals
A
9

In my case the problem was Visual Studio 2017 adding UTF-8 BOM characters to angular.json after I edited the file.

Permanent solution for Visual Studio and Angular CLI was to open the file once and save as UTF-8 without signature

  1. Go to File -> Save As.

FileSaveAs

  1. Then on Save button click on triangle and click Save with Encoding....

SaveAsPopUp

  1. From Encodings dropdown select UTF-8 Without signature -> Click OK.

AdvancedSaveOptions

Anarchy answered 14/11, 2018 at 17:41 Comment(1)
Thanks. This worked for me since am using Visual Studio 2017Branscum
C
2

Open the file in Notepad++ and change the encoding to UTF-8 then save it will work for sure :)

Courthouse answered 18/9, 2018 at 15:17 Comment(1)
Its mainly due to the syntax error in angular.json file. make sure there is a comma (,) in every end of the previous line. and also check the slash ( / and \ ) in path. use "/" instead of "\".Become
C
0

Looks like you've added a path in the angular.json file with "\" instead of "/".

Castiron answered 3/2, 2019 at 14:25 Comment(0)
B
0

Its mainly due to the syntax error in angular.json file. make sure there is a comma (,) in every end of the previous line. and also check the slash ( / and \ ) in path. use "/" instead of "\".

Become answered 26/2, 2019 at 4:46 Comment(0)
S
0

I just had the same issue as described while using the "ng g c" command. The issue was that I forgot a comma (,) while adding a second style-sheet to the angular.json file.

Hope this helps someone, Vlad

Saboteur answered 20/7, 2019 at 2:25 Comment(0)
I
0

This is due to the missing comma(,) end of the line at 76 raw in the angular.jason file. just put the comma "your_jason_code", and go to the next line.

sample:

"styles": [
              "./node_modules/bootstrap/dist/css/bootstrap.css", 
              "src/styles.css"
            ],

if you miss the comma end of the line, you will get that error.

Inandin answered 1/6, 2022 at 4:35 Comment(0)
V
-2

Make sure angular.json encoding in UTF-8 not UTF-8-BOM.

Venireman answered 16/1, 2019 at 9:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.