Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Syntax Error #2276

Closed
epiqueras opened this issue Jun 26, 2017 · 9 comments
Closed

JSON Syntax Error #2276

epiqueras opened this issue Jun 26, 2017 · 9 comments
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Comments

@epiqueras
Copy link

epiqueras commented Jun 26, 2017

./locales/en.json
./locales/en.json: SyntaxError: Unexpected token, expected ; (2:14)

  1 | {
> 2 |   "abc": 1,
    |        ^
  3 |   "hello": "2",
  4 |   "edf": "3",
@vjeux
Copy link
Contributor

vjeux commented Jun 26, 2017

JSON support hasn't yet been release, and this is not a valid JavaScript statement (it's a valid javascript expression). I'm working on the next release, so please wait a bit more :)

@vjeux vjeux closed this as completed Jun 26, 2017
@epiqueras
Copy link
Author

@vjeux
Oh, since the Readme listed a json parser I assumed it supported json. Awesome work, looking forward to the next releases!

@jbmusso
Copy link

jbmusso commented Apr 3, 2018

Interestingly, this error pops up with prettier@1.11.1 configured with the "typescript" parser.

Config file:

{
  "useTabs": false,
  "printWidth": 80,
  "tabWidth": 2,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "all",
  "bracketSpacing": true,
  "jsxBracketSameLine": false,
  "parser": "typescript"
}

See also: prettier/pretty-quick#23 (comment)

Removing the "parser": "typescript" line and using default fixes the issue.

-edit- hit post Comment button too quick.

@suchipi
Copy link
Member

suchipi commented Apr 3, 2018

@jbmusso configuring prettier with parser in your prettierrc/package.json will force prettier to use that parser for all files by default, including JSON. That's why it errors. Prettier autodetects which parser to use based on file extension so in most cases you do not need to set the parser.

@coleturner
Copy link

coleturner commented Jun 15, 2018

Experiencing this error in v1.13.x:
It was working however in v1.11.x, both are using the bablyon parser

@vjeux I believe there is a breaking change between these versions

edit: also tested v1.12 where it is working

@lydell
Copy link
Member

lydell commented Jun 15, 2018

@coleturner Prettier 1.13 fixed a bug where your parser choice in your config file was incorrectly ignored for some files (see #4633). The babylon cannot parse many JSON files because they are not valid JS programs. Some people have run into this error because they added parser: "babylon" at the top level of their .prettierrc, which is a really bad idea. See #4642 and #4638. It could be that all you need to do is removing parser: "babylon" from your .prettierrc and you should be all set. Hope this helps.

@coleturner
Copy link

Aha I see, this is an edge case then, please ignore :P

@texastoland
Copy link

I'm getting this error with no parser specified. My override was also ignored.

overrides:
  - files: "*.json"
    options:
      parser: json

@j-f1
Copy link
Member

j-f1 commented Jul 18, 2018

@texastoland Can you open a new issue and fill out the formatting template?

@prettier prettier locked as resolved and limited conversation to collaborators Jul 18, 2018
@j-f1 j-f1 added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests

8 participants