← Back to Blog

What Is JSON? Format, Syntax, and Examples Explained

JSON is a text-based data format built from 6 value types. See real examples, the 4 syntax errors that break valid JSON, how to validate it, and .NET code for reading it.

Pankaj Kumar
Senior Software Engineer — .NET, Blazor, ASP.NET Core
4+ years building production .NET and Blazor applications. Every DevToolsHub tool and article comes from real daily development work — not documentation summaries.
Published 05 Jun 2026· 6 min read · About the author →
Backend engineer who has designed JSON APIs for web, mobile, and IoT clients. Has reviewed code where a trailing comma in a config file caused a production deployment to silently fail on a Friday.
Key takeaways
  • JSON's 6 value types — string, number, boolean, null, object, and array
  • The difference between minified and formatted JSON, and when to use each
  • The 4 most common JSON syntax errors and exactly how to fix them
  • Why JSON replaced XML for REST APIs — and when XML is still the right choice
Table of Contents
Key takeaways:
  • JSON has exactly 6 value types — string, number, boolean, null, object, and array
  • Minified JSON strips whitespace for transmission; formatted JSON adds it back for readability — same data either way
  • Trailing commas, single quotes, comments, and unquoted keys are the 4 mistakes behind most "invalid JSON" errors
  • JSON replaced XML for most REST APIs because it's more compact and maps directly to native data structures — but XML still owns SOAP, Android resources, and Office document formats

What is JSON?

JSON (JavaScript Object Notation) is a text-based data format that represents structured information using just six value types — string, number, boolean, null, object, and array. Despite the word "JavaScript" in its name, JSON is completely language-independent and is supported natively by virtually every programming language in use today — Python, C#, Java, Go, Rust, Ruby, and more. It's the format behind most REST API responses, config files like appsettings.json, and structured log output.

Douglas Crockford standardised JSON in the early 2000s as a simpler alternative to XML. It was formally specified in RFC 8259 and is now the default format for REST APIs, configuration files, log data, and inter-service communication across the industry.

Want to try it immediately? Paste any JSON into the JSON Formatter to pretty-print and validate it, or paste a JSON payload into the JSON to C# Class Converter to generate a matching C# class or record in one click.

JSON syntax — the six value types

Every valid JSON document is built from exactly six value types:

  • String — text wrapped in double quotes: "Hello, world"
  • Number — integer or floating point, no quotes: 42, 3.14, -7
  • Boolean — lowercase only: true or false
  • Null — represents an absent value: null
  • Object — an unordered set of key-value pairs inside { }
  • Array — an ordered list of values inside [ ]

String values have their own escaping rules — a literal double quote or backslash inside a JSON string must be escaped as \" or \\. If you're building a JSON string value by hand from C# text that contains quotes, newlines, or backslashes, the C# String Escaper shows you the same text as a properly escaped literal so you can embed it correctly.

A complete JSON document looks like this:

{
  "name": "Pankaj Kumar",
  "role": "Senior Software Engineer",
  "active": true,
  "score": 98.5,
  "tags": ["blazor", "dotnet", "csharp"],
  "address": {
    "city": "Bangalore",
    "country": "India"
  },
  "notes": null
}

Minified vs formatted JSON

Minified JSON strips all whitespace and newlines to reduce file size, making it ideal for network transmission. Formatted JSON (also called pretty-printed) adds consistent indentation and line breaks, making it human-readable for debugging and code review.

The same data in both forms:

// Minified — 48 bytes
{"name":"Pankaj","city":"Bangalore"}

// Formatted — easier to read
{
  "name": "Pankaj",
  "city": "Bangalore"
}

Use minified JSON in HTTP responses and log files where size matters. Use formatted JSON when writing config files, committing to source control, or reviewing data during development.

How to validate JSON

JSON validation checks that your document conforms to the JSON notation described above — correct brackets, quoted keys, valid value types, no trailing commas, and no comments — and confirms it is valid JSON before you rely on it. A validator reports the exact line and character where a problem occurs.

Common validation approaches:

  • Online formatters and validators (like the DevToolsHub JSON Formatter)
  • Browser DevTools console: JSON.parse(yourString) throws a SyntaxError on invalid JSON
  • Language-native parsers: System.Text.Json in C#, json.loads() in Python
  • IDE plugins that highlight JSON errors inline

The most common JSON mistakes

These four mistakes account for the vast majority of JSON parse errors:

  1. Trailing commas — JSON does not allow a comma after the last item in an object or array. This is valid in JavaScript but strictly forbidden in JSON: {"a":1, "b":2,} is invalid.
  2. Single quotes — all strings and all keys must use double quotes. {'name': 'Pankaj'} is JavaScript, not JSON.
  3. Comments — standard JSON does not support comments. If you need comments in a config file, consider JSON5 or JSONC (used by VS Code) — but plain JSON has no // or /* */.
  4. Unquoted keys — every object key must be a quoted string. {name: "Pankaj"} is invalid JSON.

JSON vs XML

Before JSON became dominant, XML was the standard for data exchange. JSON replaced it in most web API contexts for three reasons: it is more compact (less verbose), it maps directly to data structures in every language, and it is easier for both humans and machines to parse. XML is still used in enterprise systems, document formats (DOCX, SVG), and SOAP web services, but for REST APIs, JSON is the clear choice. If you're working with an XML config file or SOAP payload in a .NET project and need the equivalent C# shape, the XML to C# Class Generator does for XML what the JSON to C# converter above does for JSON — paste the XML, get a matching class.

The JSON data format and the older XML file format solve the same underlying problem — describing structured data as text — with different tradeoffs on verbosity and readability. A .json file is just plain text in the JSON file format; there's no binary encoding or special extension handling required.

JSON in real projects

You encounter JSON constantly in modern development:

  • REST API responses — virtually every public API (GitHub, Stripe, Google Maps) returns JSON
  • Configuration filespackage.json, appsettings.json, tsconfig.json, launch.json
  • Data storage — PostgreSQL, MongoDB, and SQL Server all support native JSON columns
  • Logging — structured log formats like Serilog and Logstash use JSON for machine-parseable output
  • Inter-service messaging — event payloads in Kafka, RabbitMQ, and Azure Service Bus are typically JSON

Quick reference

  • Keys must be double-quoted strings
  • No trailing commas after the last element
  • No comments allowed in standard JSON
  • Strings must use double quotes, not single quotes
  • Numbers do not need quotes
  • Booleans are lowercase: true / false
  • Missing or absent values use null, not undefined

Every major language and platform has native JSON support built in — .NET's System.Text.Json, Python's json module, JavaScript's JSON.parse/JSON.stringify — so once a file is confirmed to be valid JSON in the correct file format, reading it is rarely the hard part; getting the syntax right in the first place is.

Try the free tool

JSON Formatter

Paste any messy or minified JSON and get back clean, indented output instantly. Validates your JSON and highlights errors — no login required.

Open JSON Formatter