JSON

What is JSON?

JSON, or JavaScript Object Notation, is a popular data exchange format rooted in JavaScript object syntax. It’s lightweight, human-readable, and widely supported across programming languages like Python, JavaScript, and Java, making it a go-to choice for sharing data between systems. Beyond objects, JSON can also represent simple arrays and strings, offering flexibility for various use cases.

Key Features of JSON

  1. JavaScript Object Syntax
    JSON is built on key-value pairs, like this: { "key": "value" }

  2. Data + Exchange Format
    "Data" refers to anything from abstract ideas to concrete measurements, facts or materials gathered from experiments, observations, or surveys. JSON structures this data in a way that’s easy to exchange between systems.
  3. Cross-Language Compatibility
    JSON adapts seamlessly to different languages:

    • JavaScript: Converts to a JavaScript object
    • Python: Becomes a dictionary (dict)
    • Java: Maps to a HashMap
  4. Simple Arrays and Strings
    JSON isn’t limited to objects. It can represent:

    • Arrays: [1, 2, 3, 4]
    • Strings: "helllo"
  • JSON Data Types

    JSON supports:

    • Number42
    • String"hello"
    • Booleantrue or false
    • Array[1, 2, 3]
    • Object{"key": "value"}
    • Nullnull
      Unlike JavaScript objects, JSON cannot include undefined or methods.

  • Serialization and Deserialization

    • Serialization: Converting data into a byte format (e.g., a string) for external use. In JavaScript, JSON.stringify() turns an object into a JSON string.

    • Deserialization: Converting that byte format back into usable data. JSON.parse() does this in JavaScript.

      const obj = { "name""Cham" }; 
      const jsonString = JSON.stringify(obj);  // {"name" : "Cham"}
      const parsedObj = JSON.parse(jsonString); // { name: "Cham" }


Why Use JSON?

JSON shines because it’s language- and framework-agnostic. It’s perfect for:

  • APIs: returns JSON data.
  • Configuration Files: Think package.json in Node.js (npm Docs).

Its simplicity and universality make it a cornerstone of modern data exchange.

Comments

Popular posts from this blog

@ModelAttribute vs @RequestBody in Validation

Side Project(a self-imposed 3-day "Hackathon" challenge)

Google: The King is Back