JSON Syntax
Can json keys have spaces?
Yes, JSON keys can contain spaces, though it is generally discouraged in practice. When using spaces in keys, you must enclose the entire key in double quotes, which is already required by JSON syntax. For example, {"user name": "John"} is valid JSON. However, spaces in keys create problems when accessing properties in JavaScript, requiring bracket notation like obj["user name"] instead of dot notation. This makes code more verbose and error-prone. Most style guides recommend using camelCase or snake_case for key names instead of spaces. Spaces can also cause issues with some query languages and database systems. For better code maintainability, API design, and developer experience, use underscores or camelCase rather than spaces in JSON keys.
Last updated: December 23, 2025
Related Questions
Can json have duplicate keys?
Learn whether JSON can have duplicate keys, what happens when they occur, and why you should avoid them for data integrity and predictability.
Can json use single quotes?
Find out if JSON can use single quotes. Learn about JSON's strict double-quote requirement and why it differs from JavaScript syntax.
Can json have comments?
Learn whether JSON supports comments and discover workarounds. Understand why standard JSON excludes comments and alternatives like JSON5.
Still have questions?
Can't find the answer you're looking for? Please reach out to our support team.