Course contentsShow
← System Design
Lesson 1138 of 1,91929. Observability: LoggingFree lesson

JSON as Log Format

Why JSON is the dominant structured logging format and its advantages for parsing and indexing.

JSON as Log Format

What you'll learn: Why JSON has become the de facto standard for structured logging and what advantages it provides over plain text.

The Dominance of JSON

JSON (JavaScript Object Notation) is the most widely adopted format for structured logs today. While you could structure logs as CSV, XML, or custom formats, JSON has won because it perfectly balances human readability with machine parseability. It's the lingua franca of modern observability tooling.

Why JSON Works So Well

Universal Parser Support: Every programming language has mature, fast JSON libraries. Every log aggregation tool (Elasticsearch, Splunk, Datadog, CloudWatch) parses JSON natively without custom configuration.

Schema Flexibility: JSON handles nested objects, arrays, and mixed types naturally. You can add new fields without breaking existing parsers:

{
  "timestamp": "2024-01-15T10:30:00Z",
  "level": "ERROR",
  "correlation_id": "abc-123",
  "user_id": 42,
  "error": {
    "type": "DatabaseTimeout",
    "message": "Connection timeout after 5000ms"
  }
}

Easy Indexing: Log storage systems automatically index JSON fields. Want all errors for user_id: 42? That's a simple query, not a regex nightmare.

Self-Documenting: Field names are explicit. No need to remember "column 7 is the user ID."

The Analogy

Think of plain-text logs as a paragraph essay—humans can read it, but extracting specific facts requires careful reading. JSON logs are like a form with labeled fields—both humans and computers can quickly find exactly what they need.

Key Takeaway: JSON became the standard for structured logging because it's universally supported, flexible for evolution, trivial to parse and index, and strikes the perfect balance between human and machine readability.