What is json?
JSON (JavaScript Object Notation) is a lightweight text format used to store and exchange data. It looks like a collection of name‑value pairs, similar to how you would write a list of items in a notebook. Because it is plain text, both humans and computers can read and write it easily.
Let's break it down
- Objects: Curly braces
{
} hold a set of key‑value pairs, e.g.,{"name":"Alice"
}. - Arrays: Square brackets [ ] hold an ordered list of values, e.g., [“red”,“green”,“blue”].
- Values: Can be strings (“text”), numbers (123), booleans (true/false), null, objects, or arrays.
- Syntax rules: Keys must be quoted strings, items are separated by commas, and there are no comments.
Why does it matter?
JSON provides a simple, language‑independent way to move data between programs, especially web browsers and servers. Its readability makes debugging easier, and its compact size speeds up network communication.
Where is it used?
- Web APIs that send data to front‑end apps (e.g., fetching weather info).
- Configuration files for tools and services.
- Storing data in NoSQL databases like MongoDB.
- Communication between microservices in cloud applications.
- Mobile apps syncing with back‑end servers.
Good things about it
- Easy to read and write for humans.
- Supported natively by most programming languages.
- Small file size compared to XML, leading to faster transfers.
- Strict syntax reduces ambiguity.
- Works well with JavaScript, the language of the web.
Not-so-good things
- No support for comments, making it harder to annotate files.
- Only a limited set of data types (no dates, binary data, etc. without custom handling).
- Strict syntax can cause errors if a single comma or quote is misplaced.
- Not ideal for very large or complex hierarchical data where a binary format might be more efficient.