Questions tagged [json5]

JSON5 is a superset of JSON that has a more flexible syntax. Use this tag for questions specifically related to the JSON5 standard, and NOT questions that are ONLY about regular JSON.

JSON5 is a superset of JSON that has a more flexible syntax that aligns with ES5 syntax (the version of Javascript most commonly used today). In addition to everything JSON supports, it adds:

  • unquoted property keys
  • single-quoted, escaped and multi-line strings
  • alternate number formats
  • comments
  • extra whitespace

The JSON5 reference implementation (json5 npm package) provides a JSON5 object that has parse and stringify methods with the same args and semantics as the built-in JSON object.

22 questions
287
votes
8 answers

Do the JSON keys have to be surrounded by quotes?

Example: Is the following code valid against the JSON Spec? { precision: "zip" } Or should I always use the following syntax? (And if so, why?) { "precision": "zip" } I haven't really found something about this in the JSON specifications.…
christianvuerings
  • 22,500
  • 4
  • 23
  • 19
135
votes
10 answers

Parsing string as JSON with single quotes?

I have a string str = "{'a':1}"; JSON.parse(str); VM514:1 Uncaught SyntaxError: Unexpected token '(…) How can I parse the above string (str) into a JSON object ? This seems like a simple parsing. It's not working though.
Coderaemon
  • 3,619
  • 6
  • 27
  • 50
20
votes
4 answers

Safely parsing a JSON string with unquoted keys

json2.js is strict requiring all object keys be double-quoted. However, in Javascript syntax {"foo":"bar"} is equivalent to {foo:"bar"}. I have a textarea that accepts JSON input from the user and would like to "ease" the restriction on double…
daepark
  • 256
  • 1
  • 2
  • 5
12
votes
2 answers

Can the Jackson parser be used to parse JSON5?

We'd like to parse JSON5 documents in the JVM, but the JSON5-specific libraries available on GitHub all appear to have very low support. As parsers are often magnets for security vulnerabilities, we'd prefer not to use a parser that isn't already…
Graham Lea
  • 5,797
  • 3
  • 40
  • 55
4
votes
3 answers

Requiring a JSON with comments in node.js

If you use typescript you can init a default tsconfig.json, and that json will have javascript // and /* */ comments in it. I've encountered a situation with ts-jest where I need to require my tsconfig and parse it, but jest is not parsing it…
Thom
  • 524
  • 1
  • 6
  • 12
3
votes
0 answers

How to add JSON5 schemas in VS Code?

I am trying to configure JSON5 schemas in my settings.json file in VS Code, [to have intellisense] I would like to do something similar to what is available today for JSON editing…
Chaipau
  • 199
  • 1
  • 5
  • 14
3
votes
2 answers

How to import a JSON5 file (as one can regular JSON) in Typescript?

I would like to import a JSON5 file into a Javascript object in the same way [one can import a JSON file](import config from '../config.json'). Shows this message on hovering but it's clearly there Cannot find module '../conf/config.json5' or its…
Zoro
  • 43
  • 5
2
votes
1 answer

Nuxt asyncData returns empty array for a json5 file with Nuxt Content

I am using the asyncData method to retrieve the content of a json5 file and I get an empty array. My file is located at content/myfile.json5 The content is : [ { id: 1 }, { id: 21 } ] And my method is : async asyncData({…
jbuiquan
  • 21
  • 5
2
votes
0 answers

Parcel: JSON5: invalid character '\'

On trying to build a react app using tailwind and postcss, it throws me this error. /mnt/c/Users/Shaleen/Documents/Visual Studio 2019/Courses/Frontend Masters/Intro to React V6/adopt-me/src/style.css:undefined:undefined: JSON5: invalid character…
Altair21
  • 505
  • 8
  • 24
2
votes
1 answer

Parsing json5/js object literals in Ada

New to Ada. Trying to work with some objects like the following {name:'Hermann',age:33} in an a project and I'd rather not write my own json parser for this. Is there either: a way for me to configure Gnatcolls.JSON to parse and write these objects…
KG6ZVP
  • 3,610
  • 4
  • 26
  • 45
2
votes
3 answers

Error while parsing config - JSON5: invalid end of input at 1:1 at syntaxError

I have tried using the node_modules/.bin/babel before.js -o after.js command to convert from es6 to compatible js. I also had to run set-executionpolicy remotesigned on windows powershell to fix error cannot be loaded because running scripts is…
Potatodragon
  • 141
  • 1
  • 2
  • 5
1
vote
1 answer

SyntaxError: JSON5: invalid character 'm' at 3:1

Babel is giving me the following error: ../../node_modules/next/dist/pages/_error.js SyntaxError: JSON5: invalid character 'm' at 3:1 My .babelrc and babel.config.cjs: /* eslint-disable no-template-curly-in-string */ module.exports = { presets:…
Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
1
vote
0 answers

TypeError: JSON5.parse is not a function

I have installed JSON5 by npm install -d -g json5 and trying to parse the json string. But it is showing me [[object Object]]JSON5.parse is not a function. What the problem actually here is? and how we can resolve this? I am using the following…
Tanmay Bairagi
  • 564
  • 5
  • 25
0
votes
0 answers

python json5 and json package inconsistent deal with surrogate pair

#!/opt/homebrew/bin/python3 #-*-coding:utf8-*- #python version 3.11.4 import json5 import json d = json5.loads('{"\\ud83d\\ude03": "ok"}') print(d) # output: {'\ud83d\ude03': 'ok'} d = json.loads('{"\\ud83d\\ude03": "ok"}') print(d) # output:…
Green
  • 121
  • 1
  • 3
0
votes
0 answers

Vue.js - Display JSON file in Codemirror, but keep file format intact

I've been looking around for quite some time now, because I'm having an edge case situation where I need to be able to show/edit a JSON file, which is already done, but my issue being that I need this JSON file to stay identical to the source…
ItemME
  • 1
1
2