A clear understanding of JSON syntax is fundamental for effective data manipulation and error prevention. JSON is a text-based format that is language-agnostic, though its syntax is derived from JavaScript object literals.
JSON Data Types
JSON supports the following data types:
- Strings: Unicode character sequences enclosed in double quotes (
""
). Example: "Tooler.Guru"
. Single quotes are not permitted. Escape sequences (e.g., \n
, \"
) are used for special characters. - Numbers: Integers or floating-point values. Examples:
42
, -17.5
, 2.99e8
. Octal/hexadecimal formats and leading zeros (for non-zero numbers) are invalid. - Booleans: Literal values
true
or false
(unquoted). - Arrays: Ordered lists of values, comma-separated, enclosed in square brackets (
[]
). Example: ["config", 100, false]
. Elements can be of mixed types. - Objects: Unordered collections of key/value pairs, comma-separated, enclosed in curly braces (
{}
). Keys must be strings in double quotes. Example: {"id": "A-001", "active": true}
. - Null: Represents an empty or non-existent value, literal
null
(unquoted).
JSON does not natively support comments, undefined
, functions, or Date objects (dates are typically serialized as ISO 8601 strings).
Core JSON Structures
The two primary structural elements are:
- Objects (
{}
): Represent entities with named properties (key-value pairs). - Arrays (
[]
): Represent ordered collections or lists of items.
These structures can be nested to form complex data hierarchies, allowing for representation of intricate data models.
Common JSON Syntax Issues
Frequent sources of JSON validation errors include:
- Comma Misplacement: Missing commas between elements/pairs, or extraneous trailing commas (e.g.,
{"a":1, "b":2,}
is invalid in standard JSON). - Quoting Errors: Failure to use double quotes for all string values and all object keys.
- Bracket/Brace Imbalance: Unmatched
{ }
or [ ]
. - Invalid Value Types: Use of JavaScript-specific values like
undefined
or NaN
. - Unescaped Characters: Special characters within strings (e.g., quotes, backslashes) not being properly escaped.
- Inclusion of Comments: Standard JSON parsers do not process comments.
This editor's "JSON syntax validator" function assists in identifying and locating such errors.