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

Still have questions?

Can't find the answer you're looking for? Please reach out to our support team.