Back to blog
Fundamentals7 min read

JSON Objects and Keys Explained for Beginners

Understand JSON objects: keys and values, the double-quote rule, nesting, duplicate keys, unordered semantics, and how objects differ from arrays — with practical examples.

By Saifur Rahman Shochib

The object is the heart of JSON — the curly-brace structure of key-value pairs that represents everything from a user profile to an API configuration. Objects are simple to read but have a few rules (and quirks like duplicate keys and ordering) that matter once you build real systems. This guide explains JSON objects clearly, with the rules and the patterns you will use every day.

What is a JSON object?

A JSON object is an unordered collection of key-value pairs wrapped in curly braces: {"name": "Ada", "age": 36}. Each pair has a key (always a double-quoted string) and a value (any JSON type), separated by a colon, with pairs separated by commas. Objects map directly onto dictionaries, hash maps, and structs in programming languages.

An object is key-value pairs in curly bracesjson
{ "name": "Ada", "age": 36, "active": true }

The rules for keys

  • Keys must be strings wrapped in double quotes — single quotes and unquoted keys are invalid in standard JSON.
  • A colon separates each key from its value.
  • Pairs are separated by commas, with no trailing comma after the last pair.
  • Values can be a string, number, boolean, null, array, or another object.

Nesting objects

Object values can themselves be objects, which is how JSON represents hierarchy. A user object might contain an address object with its own street and city keys: {"user": {"address": {"city": "Paris"}}}. There is no practical limit to nesting depth, which is what lets JSON model complex, tree-shaped data.

Object values can be objects — that is nestingjson
{ "user": { "address": { "city": "Paris" } } }

Objects are unordered

By specification, the keys in a JSON object have no guaranteed order — {"a":1,"b":2} and {"b":2,"a":1} are the same object. Most parsers happen to preserve insertion order in practice, but you should never rely on key order for correctness, and tools that compare JSON treat objects as unordered. If order matters, use an array.

Duplicate keys

The JSON specification does not forbid duplicate keys, but it does not define what they mean either, so behavior is implementation-dependent — most parsers keep the last occurrence and silently drop the earlier ones. Duplicate keys are a latent bug: avoid producing them, and be suspicious of any payload that contains them.

Working with objects

To trim an object down to the fields you need — or strip sensitive ones before sharing — a pick and omit tool whitelists or blacklists top-level keys. To explore a deeply nested object, a tree viewer reveals the hierarchy at a glance, and a formatter makes a compact object readable. These make large objects manageable without manual editing.

Frequently asked questions

What is a JSON object?

A JSON object is an unordered set of key-value pairs inside curly braces, like {"name": "Ada"}. Keys are double-quoted strings and values can be any JSON type. Objects map to dictionaries or structs in code.

Do JSON keys have to be in double quotes?

Yes. In standard JSON, every key must be a string wrapped in double quotes. Single quotes and unquoted keys are invalid — though relaxed supersets like JSON5 allow them for hand-edited files.

Are JSON object keys ordered?

No. The JSON specification treats object keys as unordered, so you should not rely on key order. Most parsers preserve insertion order in practice, but comparisons and correctness should never depend on it.

Can a JSON object have duplicate keys?

The spec does not forbid them but leaves the behavior undefined. Most parsers keep the last occurrence and drop earlier ones. Duplicate keys are error-prone, so avoid creating them.

What is the difference between a JSON object and an array?

An object is an unordered collection of named key-value pairs in curly braces; an array is an ordered list of values in square brackets accessed by index. Use objects for named fields and arrays for lists.

Related tools

Try these tools

Keep reading

Related guides