JavaScript

JavaScript is a high-level, interpreted programming language that is widely used for web development. Initially designed as a client-side scripting language, it runs directly in web browsers, enabling dynamic and interactive user experiences. JavaScript can now be used for server-side development as well.

JSON Syntax

15 April 2025 | Category:

JSON (JavaScript Object Notation) syntax is a set of rules that define how data is structured in JSON format. It is a lightweight, text-based format that is used to store and transfer data, especially between a client and a server.

The syntax is derived from JavaScript object literals, but JSON is a string format that is language-independent.


📜 JSON Syntax Rules

  1. Data is written as key/value pairs.
  2. Keys must be strings, written inside double quotes.
  3. Values can be:
    • String
    • Number
    • Boolean
    • Null
    • Object (another JSON object)
    • Array
  4. Objects are wrapped in { }.
  5. Arrays are wrapped in [ ].
  6. Commas separate pairs or elements.
  7. JSON does not support comments.

✅ JSON Syntax Example

{
  "name": "John",
  "age": 28,
  "isEmployed": true,
  "skills": ["HTML", "CSS", "JavaScript"],
  "address": {
    "city": "Mumbai",
    "zip": "400001"
  },
  "spouse": null
}

🔍 Explanation of Syntax

ElementTypeDescription
"name"StringMust be in double quotes
28NumberNo quotes required
trueBooleanMust be lowercase (true or false)
["HTML",...]ArrayList of values in square brackets
{...}ObjectNested object inside the main object
nullNullRepresents an empty value

❌ Invalid JSON Examples

Here are some examples that will result in errors:

1. ❌ Single Quotes

{ 'name': 'John' }

✅ Use double quotes: { "name": "John" }

2. ❌ Trailing Commas

{
  "name": "John",
  "age": 28,
}

✅ Remove the last comma.

3. ❌ Comments

{
  "name": "John" // This is not allowed
}

✅ JSON does not support comments. Remove them.


🧠 Summary

  • JSON syntax is strict and simple.
  • It is based on key/value pairs.
  • Use double quotes for all keys and string values.
  • Values must be valid types: string, number, object, array, boolean, or null.
  • Do not include functions or comments in JSON.