question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrongly formats JSON with array as root as JS

See original GitHub issue

When having a file which vs code recognizes as JSON (e.g. test.json) which contains an array as the root entry it gets formatted as it would be a javascript file.

Input:

[{"test":"test"}]

Output:

;[{ test: 'test' }]

This does not seem to be a prettier issue because running prettier in the terminal on the .json file directly does not cause the issue.

Custom Settings: .prettierrc:

arrowParens: always
singleQuote: true
parser: babylon
semi: false
printWidth: 100
trailingComma: es5

Relevant VS Code Settings:

  ...
  "prettier.parser": "babylon",
  "prettier.printWidth": 100,
  "prettier.semi": false,
  "prettier.singleQuote": true,
  "prettier.trailingComma": "es5",  
  "eslint.autoFixOnSave": true,
  "prettier.eslintIntegration": true,
  ...

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
CiGitcommented, Nov 8, 2018

Try removing “parser”: “babylon” from your config file

0reactions
github-actions[bot]commented, May 10, 2020

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set root JSON object value to array - Stack Overflow
So, simply JSON.parse(eventstring).Array1 . Is that what you're looking for? Incidentally, most "naked" primary data types are also ...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
Solve common issues with JSON in SQL Server
I want to produce complex JSON with several arrays on the same level. FOR JSON PATH can create nested objects using paths, and...
Read more >
RFC 7159: The JavaScript Object Notation (JSON) Data ...
JSON defines a small set of formatting rules for the portable representation of ... RFC 7159 JSON March 2014 The terms "object" and...
Read more >
What Is JSON and How to Handle an “Unexpected Token” Error
Values can be strings, arrays, or any other data that can be ... JSON format is quite similar to JavaScript objects, but it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found