Javascript Object Notation (JSON)

The Web’s Favorite Data Format

Author

Chuck Nelson

Published

September 13, 2025

1 Demystifying JSON: The Web’s Favorite Data Format

Intro to JSON

Extensible Markup Language (XML) is a powerful tool for structured data, but its verbosity can be a drawback. That’s where JSON (JavaScript Object Notation) comes in. It’s a lightweight, easy-to-read, and compact data format that has become the dominant choice for data exchange on the web.

1.1 A Quick Look Back: How JSON Came to Be

JSON wasn’t a formal standard at first; it emerged organically as a way to send data between web servers and a browser’s JavaScript. It was a reaction to the complexity and verbosity of XML, which required extensive parsing and was often too “heavy” for fast-moving web applications. The first formal specification for JSON was published in 2006, and its simplicity and direct mapping to JavaScript objects quickly made it a web standard.

1.2 What Exactly Is JSON?

JSON is a text-based format for representing structured data based on JavaScript object syntax. It uses key-value pairs and arrays, which makes it extremely intuitive for developers to read and work with. Unlike XML, it has a very simple and strict syntax, making it fast to parse.

Here’s an example of what a JSON file might look like for the same bookstore data:

{
  "bookstore": {
    "book": [
      {
        "category": "fiction",
        "title": "The Hitchhiker's Guide to the Galaxy",
        "author": "Douglas Adams",
        "year": 1979,
        "price": 12.99
      },
      {
        "category": "science",
        "title": "Cosmos",
        "author": "Carl Sagan",
        "year": 1980,
        "price": 15.50
      }
    ]
  }
}

View the file

Notice how much less “markup” there is compared to XML. The data is more concise and directly resembles the data structures used in many modern programming languages.

1.3 Where is JSON Used? The Everywhere Format

Because of its simplicity and efficiency, JSON is ubiquitous in today’s digital world.

  • Web APIs: Nearly all modern web services and APIs use JSON for sending and receiving data. When your phone app talks to a server, it’s almost certainly using JSON.

  • Configuration Files: Just like XML, JSON is popular for configuration, especially for JavaScript-based tools and services.

  • NoSQL Databases: Many NoSQL databases (like MongoDB and Couchbase) store data in a JSON-like format.

  • Logging and Analytics: It’s a common format for structured logging in server-side applications.

1.4 Making JSON Work for You: The Power of jq

Since JSON doesn’t have a built-in schema or querying language like XML, specialized tools have emerged to handle it. One of the most powerful is a command-line tool called jq. It’s a “sed for JSON data,” and it’s invaluable for validating, formatting, and querying JSON files.

1. Pretty-Printing a JSON File If you have a compressed JSON file all on one line, jq can easily format it to be more readable.

echo '{"bookstore":{"book":[{"title":"The Hitchhiker\'s Guide to the Galaxy"}]}}' | jq .
{
  "bookstore": {
    "book": [
      {
        "title": "The Hitchhiker's Guide to the Galaxy"
      }
    ]
  }
}

2. Querying a JSON File jq uses a powerful query syntax to extract specific pieces of data.

# Get the title of the first book
cat bookstore.json | jq '.bookstore.book[0].title'

# Output:
# "The Hitchhiker's Guide to the Galaxy"

You can also filter arrays and get multiple values:

# Get all book titles
cat bookstore.json | jq '.bookstore.book[].title'

# Output:
# "The Hitchhiker's Guide to the Galaxy"
# "Cosmos"

The query syntax is intuitive. The . represents the current object, and you use keys to navigate down the hierarchy. Arrays are accessed with [] or [] to get all elements.

3. Validating a JSON File By simply running jq with the . filter, it will return an error if the JSON is invalid, making it a quick and easy validator.


1.5 JSON Schema: The Equivalent of an XSD

While JSON doesn’t have a built-in schema like XML, JSON Schema provides a powerful way to define and validate the structure, content, and data types of a JSON document. This is crucial for building reliable APIs and applications where data consistency is a priority.

Here is a JSON Schema for our bookstore data. This schema ensures that the bookstore object contains an array of book objects, and that each book has the required fields with the correct data types.

{
  "$schema": "[http://json-schema.org/draft-07/schema#](http://json-schema.org/draft-07/schema#)",
  "$id": "[http://example.com/bookstore.schema.json](http://example.com/bookstore.schema.json)",
  "title": "Bookstore",
  "description": "The schema for a simple bookstore catalog.",
  "type": "object",
  "properties": {
    "bookstore": {
      "type": "object",
      "properties": {
        "book": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "category": { "type": "string" },
              "title": { "type": "string" },
              "author": { "type": "string" },
              "year": { "type": "integer" },
              "price": { "type": "number" }
            },
            "required": ["category", "title", "author", "year", "price"]
          }
        }
      },
      "required": ["book"]
    }
  },
  "required": ["bookstore"]
}

View the file

When you use a validator, you provide both the JSON Schema and your JSON data file. The validator will check the data against all the rules in the schema, reporting any errors if a value is missing, has the wrong type, or doesn’t match a pattern. This is an essential step for robust data handling.


1.6 Installing jq

The jq tool is a cross-platform powerhouse that can be easily installed on a variety of operating systems using their respective package managers.

On Linux, you can use the system’s package manager.

  • For Red Hat-based distros (e.g., Fedora, CentOS, RHEL):
sudo dnf install jq
  • For Debian-based distros (e.g., Ubuntu, Debian):
sudo apt-get install jq

On macOS, the easiest way to install jq is with the Homebrew package manager.

brew install jq

On Windows, you have a couple of excellent package managers to choose from:

  • Winget (Windows Package Manager, built into modern Windows 10/11):
winget install stedolan.jq
  • Scoop (a community-driven command-line installer):
scoop install jq

For a direct download, you can also grab the executable from the official website and add it to your system’s PATH.

1.7 Conclusion

JSON is a cornerstone of modern web development and a vital skill for anyone working with data. Its concise syntax and direct mapping to programming language data structures have made it the go-to format for APIs, configurations, and more. While XML still has its place, particularly in highly structured and validated enterprise systems, JSON’s flexibility and simplicity have cemented its status as the default for web data exchange.

So, dive into JSON, and be sure to spend some time learning jq—it’s one of the most useful tools for working with JSON data.

Back to top