JSON (JavaScript Object Notation) is a lightweight data interchange format that is widely used for communication between server and client side applications. It’s easy to read and understand, making it an ideal choice for transmitting data over the web. But how do you create JSON objects in JavaScript? Let’s find out!
What are JSON Objects?
A JSON object is a collection of key-value pairs enclosed in curly braces {}
. The keys must be strings, while the values can be strings, numbers, booleans, arrays, or even other JSON objects. Here's an example of a JSON object:
{
"name": "John Doe",
"age": 35,
"isMarried": true,
"skills": ["JavaScript", "HTML", "CSS"],
"address": {
"street": "Main St.",
"city": "New York",
"state": "NY",
"zip": "10001"
}
}
How to Create JSON Objects in JavaScript:
There are three ways to create JSON objects in JavaScript: