Write JSON objects and property names

What a JSON object is, how to write valid property names, what formatting and reformatting change, and how to keep JSON usable after copying and sharing.

A JSON object is a set of name/value pairs inside curly braces. It is the most common structure in JSON configuration files, API payloads and data exports. This guide explains how to write objects and property names that parsers accept, what formatting tools actually change, and where copying and sharing can quietly break otherwise valid JSON. It draws on the JSON specifications (RFC 8259 and ECMA-404) and general, verifiable parsing behavior. No specific formatter, validator or editor was tested for this article, so tool-specific behavior is not covered.

What a JSON object is

An object starts with an opening curly brace and ends with a closing one. Inside, each member is a name, a colon, and a value. Commas separate members. The name is always a string in double quotes. The value can be a string, a number, another object, an array, true, false or null. The specification describes an object as an unordered collection, so the meaning of the data should not depend on the order of its members.

{
  "id": 1042,
  "name": "Ada",
  "active": true,
  "tags": ["admin", "editor"],
  "address": {
    "city": "Springfield",
    "zip": null
  }
}

JSON is stricter than the JavaScript object literals it resembles. The following are not valid JSON, even though many people expect them to work:

  • Unquoted names, such as name: "Ada"
  • Single-quoted strings or names, such as 'name': 'Ada'
  • A trailing comma after the last member
  • Comments of any kind
  • Values such as undefined, NaN, Infinity, functions or dates written as bare literals
  • Numbers with leading zeros, a leading plus sign, or hexadecimal notation

Property names and the idea of a "JSON identifier"

JSON has no concept of an identifier in the programming-language sense. A property name is any JSON string. Names such as "first-name", "2nd place", "" (the empty string) and "日付" are all valid JSON. The constraints come from the code that consumes the data. In JavaScript, for example, a name with a hyphen or space has to be read with bracket notation, not dot notation. Many other languages and data-binding libraries expect names to map onto variable or field names. Choose names that suit your consumers, not just the parser.

People searching for "JSON identifier" may mean one of three different things, so it helps to pin down which:

  • A property name, also called a key or member name
  • An ID field inside the data, such as "id" or "userId", which is an ordinary name/value pair with no special meaning in JSON itself
  • The "$id" keyword in JSON Schema, which identifies a schema; this belongs to the JSON Schema specification, not core JSON

Practical guidance for names that travel well:

  • Pick one naming style, such as camelCase or snake_case, and use it throughout
  • Keep names unique within each object; the specification says names SHOULD be unique and warns that behavior with duplicates is unpredictable, since some parsers keep the last value, some keep the first and some reject the input
  • Prefer plain ASCII letters, digits and underscores when the data will be mapped to code or used across many systems
  • Avoid styled Unicode lookalikes in names, covered below

What formatting and reformatting actually change

The word "formatting" covers operations that differ in a way that matters. Some change only the presentation. Others change the stored characters, and some can change the data itself.

Operation | What changes | Effect on data
Syntax highlighting in an editor or viewer | Display only; the file is untouched | None
Whitespace-only pretty-printing or minifying | Spaces, tabs and line breaks between tokens | None; JSON ignores whitespace between tokens
Parse and re-serialize (what many formatters do) | The whole text is regenerated from the parsed data | Usually none, but it can alter details listed below
Key sorting | Member order | None under the spec, but it matters to anything that wrongly depends on order or compares raw text
Escaping or unescaping characters | How characters are written, such as é versus \u00e9 | None after parsing; the raw text differs

When a tool parses and then re-serializes JSON, the output depends on that tool's parser. Depending on the implementation, it may:

  • Drop duplicate keys, keeping only one value
  • Rewrite numbers, for example 1.0 becoming 1 or 1e2 becoming 100
  • Lose precision in large integers or long decimals, because many parsers store numbers as IEEE 754 double-precision values; integers beyond 9007199254740991 cannot all be represented exactly
  • Normalize escape sequences in strings
  • Change member order

Check the output before replacing the original if the data includes large IDs, monetary values, duplicate keys, or a signature or hash computed over the exact text. In those cases, a whitespace-only formatter or a parser with arbitrary-precision number support is the safer choice. For large IDs, storing them as strings avoids the problem entirely.

Unicode in names: same look, different key

JSON compares property names character by character after escapes are resolved. So "a\u0062" and "ab" are the same name. JSON does not apply Unicode normalization or visual matching, and that has consequences:

  • "café" written with a precomposed é (one code point) and "café" written as e plus a combining accent (two code points) are different keys, even though they look identical
  • Names produced by "fancy font" generators, which substitute mathematical bold, italic or script letters from other Unicode blocks, are different characters from ordinary letters; a key written as bold-looking "name" will not match "name"
  • Lookalike letters from other scripts, such as Cyrillic а in place of Latin a, also produce a different key
  • Characters outside the Basic Multilingual Plane, including most emoji, are escaped as two \u sequences (a surrogate pair), so an escaped emoji name looks very different from its unescaped form

If a lookup fails even though the key looks right, compare the code points rather than the rendered text. Many editors and command-line tools can show the escaped form.

Will the JSON stay valid after copying or sharing?

Valid JSON can become invalid when it passes through software that treats it as prose. The specification allows only four whitespace characters between tokens: space, horizontal tab, line feed and carriage return. Common ways sharing breaks JSON:

  • Word processors, email clients and some chat apps can turn straight double quotes into curly quotes, which parsers reject
  • Non-breaking spaces or zero-width characters picked up from web pages or documents are not JSON whitespace and cause errors outside strings
  • A byte order mark at the start of a file is not allowed by the specification for generated JSON; parsers may ignore it but are not required to
  • Text encodings other than UTF-8 can garble non-ASCII characters; the specification requires UTF-8 for JSON exchanged between systems that are not part of a closed ecosystem
  • Some destinations wrap long lines or collapse indentation, which is harmless to validity but hurts readability

To reduce these risks, share JSON as a file attachment or inside a code block, where the destination supports one, rather than as running text. Validate it after pasting into a new environment. Which destinations alter quotes or whitespace depends on their settings and versions. None were tested for this article, so confirm with a short sample in your own environment.

On accessibility: deeply nested, minified JSON is hard to follow for anyone, and harder still when read aloud by a screen reader. Indentation and line breaks carry structure visually, but braces, brackets and quotes may be announced as individual symbols depending on the assistive technology and its punctuation settings. No specific screen reader was tested here. When people rather than programs are the audience, a plain-text or tabular summary of the key values usually serves better than raw JSON.

Is formatting JSON suitable for your use?

For most purposes, yes. Pretty-printing makes objects easier to read, review and diff, and minifying reduces size for transfer. Neither changes the data when the tool only adjusts whitespace. The deciding tradeoff is whether the tool parses and regenerates the text. If it does, it can silently change numbers, duplicate keys or the exact bytes, which matters for precise numeric data, signed payloads and byte-for-byte comparisons.

Plain text or a prose summary is preferable when:

  • The reader is a person who needs a few values, not a program that needs the structure
  • The destination is likely to alter quotes or whitespace and cannot accept attachments or code blocks
  • The content will be read by assistive technology and the nesting adds noise rather than meaning

Gaps in this review: no specific formatter, validator, editor or messaging destination was tested, and no measurements were taken. Behavior described for "some parsers" or "some destinations" reflects what the specification permits, not observed results from named tools. Check any particular tool against its documentation or a small test case before relying on it.