Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP W3.CSS C C++ C# HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

JS Tutorial

JS Home JS Introduction JS Where To JS Output JS Syntax JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Timers JS Objects JS Scope JS Dates JS Temporal  New JS Arrays JS Sets JS Maps JS Iterations JS Math JS RegExp JS Data Types JS Errors JS Debugging JS Style Guide JS Reference JS Projects  New JS Versions JS HTML DOM JS HTML Events JS HTML First

JS Advanced

JS Functions JS Objects JS Classes JS JSON JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Browser API JS Web API JS Graphics

Old Technologies

JS AJAX JS jQuery JS JSONP

JS Examples

JS Examples

JavaScript JSON Values

JSON Value Types

In JSON, values must be one of the following data types:

Type Example
String "John"
Number 30
Object {"name":"John"}
Array ["red","green"]
Boolean true
Null null
JSON Object

JSON Objects

A JSON object is enclosed in curly braces.

A JSON object contains one or more name/value pairs.

Example

{
  "name": "John",
  "age": 30,
  "city": "New York"
}

Names must be strings enclosed in double quotes.

Values can be any valid JSON value.


Object Values

In JSON, an object value is the data assigned to a specific key within an object.

TypeDescription
StringA sequence of characters enclosed in double quotes
NumberAn integer or floating-point number
BooleanThe literal values true or false
NullThe literal value null to indicate the absence of a value
ArrayAn list of values enclosed in square brackets
ObjectA collection of key/value pairs enclosed in curly braces

Property values can be objects.

Example

{
"employee":{"name":"John", "age":30, "city":"New York"}
}

Objects as values in JSON must follow the JSON syntax.

Property values can be arrays.

Example

{
"employees":["John", "Anna", "Peter"]
}

JSON Arrays

A JSON array is enclosed in square brackets.

An array contains an ordered list of values.

Example

[
  "Ford",
  "Volvo",
  "BMW"
]

Array values can be any valid JSON value.


Nested Values

Objects and arrays can contain other objects and arrays.

Example

{
  "name": "John",
  "age": 30,
  "address": {
    "city": "New York",
    "country": "USA"
  },
  "hobbies": [
    "Reading",
    "Cycling",
    "Photography"
  ]
}

Nested objects and arrays make it possible to represent complex data structures.



JSON String values

A JSON string value is a sequence of zero or more Unicode characters enclosed in double quotes.

Examples

""
"Hello World!"
"He said, \"Hello!\""
"\u00A9 2026"
{
  "name": "John"
  "city" : "New York"
}

JSON strings represent special characters using a backslash (\) escape syntax:

  • \" for double quotes
  • \\ for backslashes
  • \n for a newline
  • \t for a tab
  • \uXXXX for exact Unicode characters

To be valid, JSON strings require double quotes (unlike JavaScript, which permits single quotes).


JSON Number Values

JSON number values can be integers or floating-point numbers.

Example

{
  "age": 30,
  "height": 1.82
  "speed_of_light": 2.997e8
}

JSON does not distinguish between different numeric types. It treats integers and floating-point decimals under a single "number" category.

TypeDescriptionExample
IntegersPositive or negative whole numbers -7
42
FractionsNumbers containing a decimal point
followed by at least one digit
-0.5
3.14
ExponentsNumbers using e/E to indicate power of 10 1.0e-2 for 0.01
2.5E3 for 2500

JSON numbers requires absolute structural precision.

Many formats allowed in standard programming languages will break a JSON parser:

ErrorDescription
No Quotes "42" turns the value into a JSON string.
No Leading Zeros Integers can not be padded with zeros (05).
No Leading Plus Signs Numbers cannot start with plus (+42).
No Number Constants NaN, Infinity, and -Infinity are invalid.
No Non-DecimalHexadecimal and Octal formats are invalid (0x7A).

JSON Boolean Values

JSON supports the Boolean values true and false.

Example

{
  "member": true,
  "student": false
}
RuleDescription
No Quotation "true" turns the value into a JSON string.
Lowercase Variations like True, FALSE, or True are ivalid
No Numbers JSON does not accept numbers like 1 or 0 as boolean replacements

JSON Null

The value null represents an empty value.

Example

{
  "middleName": null
}

undefined Is Not a JSON Value

JSON supports null, but not undefined.

Wrong

{
  "city": undefined
}

Correct

{
  "city": null
}

Functions Are Not JSON Values

Wrong

{
  "greet": function() {
    return "Hello";
  }
}

Unsupported JavaScript Values

JSON has a small, strict syntax.

These JavaScript values cannot be represented in JSON:

JavaScript Value JSON
Function No
Date No
Symbol No
BigInt No
NaN No
Infinity No
undefined No

These values must be converted before they can be stored as JSON.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->