CST463 · S7 CSE

Understanding JSON

Key-value pairs, why JSON matters for data interchange, its data types and practical examples.

Module 5 Back to CST463 hub

Source: json_guide.pdf — course material by Kiran V.K., published here so it is readable without a Google account.

JSON (JavaScript Object Notation) is a foundational concept in modern web development and data interchange. At its core, JSON is based on key-value pairs, making it highly intuitive and easy to use. This document aims to provide an in-depth understanding of JSON, its importance in data interchange, the various data types it supports, and practical examples.

The Essence of JSON: Key-Value Pairs

Everything in JSON is viewed as key-value pairs, making it analogous to a dictionary in many programming languages. This structure is what makes JSON so versatile and easy to understand. {key₁: value₁, key₂: value₂, ..., keyₙ: valueₙ}

Why JSON? Key Benefits:

JSON Data Types

String

"name": "John Doe"

Number

"age": 30

Object

"address": { "street": "123 Elm Street", "city": "Anytown" }

Array

"hobbies": ["Reading", "Photography"]

Boolean

"isStudent": true

Null

"mentor": null

Practical Example: Representing a Student Object

Note :Each key in a JSON object is a string enclosed in double quotes Consider a Student object, which we will represent in JSON format.

Student Object Attributes:

JSON Representation: { "name": "Jane Doe", "age": 22, "courses": ["Computer Science", "Mathematics", "Physics"], "address": { "street": "123 Elm St", "city": "Techville", "zipCode": 12345 } }

Comparison with Other Data Interchange Formats

JSON is one among several data interchange formats such as XML, YAML, CSV, Protobuf, and EDI. Each has its unique features, but JSON is often favored for its simplicity and readability.

Conclusion

JSON's key-value pair structure is a simple yet powerful way to represent data. Its widespread support across programming languages and its ability to represent complex data structures make it an indispensable tool for professionals in web development and data handling.