JavaScript Tutorial
JS - Introduction JS - Basic JS - Placement JS - Output JS - Statements JS - Syntax JS - Variables JS - Comments JS - Data Types JS - Operators JS - Operator Precedence JS - Condition JS - Switch JS - Functions JS - Objects JS - Loops For JS - Loops While JS - Break JS - Strings JS - String Methods JS - Numbers JS - Number Methods JS - Arrays JS - Array Methods JS - Array Iteration JS - Events JS - Event Listener JS - Event Propagation JS - Date JS - Math JS - Random JS - Boolean JS - Type Conversion JS - RegExp JS - Exception JS - Scope JS - Debugging JS - Hoisting JS - Strict Mode JS - this Keyword JS - Mistakes JS - Best Practices JS - Performance JS - Form Validation JS - ES6 Features
JS Objects
Object Definitions Object Properties Object Methods Object Constructors Object Prototypes
JS Functions
Function Definitions Function Parameters Function Call Function Apply Function Closures
JS HTML DOM
DOM Introduction DOM Methods DOM Selectors DOM HTML DOM CSS DOM Attributes DOM Navigation
JS Browser BOM
JS - Window JS - Screen JS - Location JS - History JS - Navigator JS - Popup Alert JS - Timing JS - Cookies
JS AJAX
AJAX - Introduction AJAX - XMLHttp AJAX - Request AJAX - Response AJAX - PHP
JS JSON
JSON - Introduction JSON - Syntax JSON - Data Types JSON - Parse JSON - Stringify JSON - Objects JSON - Arrays JSON - PHP JSON - JSONP
JS References
JavaScript Reference JavaScript Methods HTML DOM Reference

JSON Objects

JSON objects can be created with JavaScript.

JSON objects are surrounded by curly braces {}.

JSON objects are written in key/value pairs.

Keys must be strings, and values must be a valid JSON data type.

Keys and values are separated by a colon(:) and each key/value pair is separated by a comma(,).


Creating JSON Object

The following example shows creation of an object in JavaScript using JSON:

Run code

Accessing Object Values

In order to access object values we can use dot (.) notation:

Run code

We can also access object values by using bracket ([]) notation:

Run code

Looping Through an Object

We can loop through object properties by using the for-in loop.

The following example gets each property name of the JSON object:

Run code

The following example gets each property value of the JSON object:

Run code

Nested JSON Objects

Objects can be nested inside other objects. Each nested object must have a unique access path.

We can access nested JSON objects by using the dot (.) notation or bracket ([]) notation:

Run code

Modifying Object Values

Use the dot (.) notation to modify any value in a JSON object:

Run code

We can also modify object values by using bracket ([]) notation:

Run code

Delete Object Properties

Use the delete keyword to delete properties from a JSON object.

Run code