</>
ValidateHTML

Unquoted Property Keys in JSON

In JavaScript, object keys don't need quotes if they are valid identifiers. In JSON, every key must be a double-quoted string, no exceptions. This is one of the most common mistakes when converting JavaScript objects to JSON.

Why It Matters

The JSON parser fails at the first unquoted key. This is a frequent source of bugs when developers manually write JSON or copy JavaScript objects into .json files.

Common Causes

  • Copying a JavaScript object literal where keys are bare identifiers like name or age.
  • Hand-writing JSON and forgetting that keys, not just values, must be quoted.
  • Converting from YAML or another format whose serializer left keys unquoted.

Code Examples

Invalid JSON
{
  name: "John",
  age: 30,
  isActive: true
}
Valid JSON
{
  "name": "John",
  "age": 30,
  "isActive": true
}

How to Fix

  • 1Wrap every property name in double quotes.
  • 2Use JSON.stringify() in JavaScript to automatically generate valid JSON from an object.
  • 3If converting from YAML or another format, ensure keys are quoted in the output.
  • 4Configure your editor to highlight JSON syntax errors with a JSON language mode.

Frequently Asked Questions

Why does JavaScript allow unquoted keys but JSON does not?
In JavaScript an object key can be any valid identifier, so quotes are optional. JSON, per RFC 8259, requires every name in an object to be a double-quoted string. There are no exceptions, even for simple keys.
What is the fastest way to quote all my keys correctly?
If the data is already a JavaScript object, run JSON.stringify(obj) and it produces fully quoted, valid JSON. For raw text, an editor find-and-replace or a JSON formatter is the reliable fix.
Can a JSON key be a number or contain spaces?
Yes, as long as it is a double-quoted string. "123" and "first name" are both valid keys. The value between the quotes can be anything; it just has to be quoted.

Check Your JSON Now

Our JSON validator detects this error automatically and shows the exact line and column.

Open JSON Validator
Recommended

Cloudways · Managed Cloud Hosting

Fix this JSON error, then deploy on Cloudways managed cloud (AWS, GCP, DigitalOcean).

Free 3-day trial · 30% off 3 months + free site migration with code MIGRATE303

Start free trial

Related JSON Errors

View all JSON errors