Joynex
← Articles

What Is JSON

Introduction

JSON shows up in config files, API responses, and databases. If you’ve ever opened a response in the Network tab or edited a config file, you’ve already seen it. Here we’ll cover what it is, why it’s used, and how to avoid the usual mistakes. JSON has become the default interchange format for web and mobile applications because it is lightweight, human-readable, and supported by every major language and runtime. Building a REST API, storing config, or passing data between services—a solid grasp of JSON syntax and tooling will save you from subtle bugs and integration headaches.

What Is JSON

What Is What Is JSON

JSON (JavaScript Object Notation) is a text format for structured data. It’s defined by ECMA-404 and RFC 8259. You get objects with key–value pairs, arrays, strings in double quotes, numbers, and the literals true, false, and null. No comments, no trailing commas, no single quotes—so any language can parse it. It’s not “a JavaScript object”; it’s a string that describes data. You turn that string into a value with JSON.parse() and turn a value back into a string with JSON.stringify(). JSON was derived from JavaScript literals but is strictly a data format: no functions, no undefined, no dates or binary types. The simplicity of the spec is why parsers and generators exist for virtually every language, and why JSON has largely replaced XML for APIs and configuration. Keys in objects must be unique; duplicate keys are allowed by the spec but behavior is implementation-defined, so avoid them.

Why It Matters

Most REST APIs return JSON. Frontends and backends exchange config, payloads, and state as JSON. If the string is invalid, parsing fails and your integration breaks. Knowing the rules (double-quoted keys, no trailing commas, valid escapes) lets you fix bad payloads and choose the right validators and formatters. Beyond correctness, JSON affects performance and security: very large payloads can slow parsing and memory use, and parsing untrusted JSON with eval() or similar can execute code. Using the standard parser and validating or constraining the shape of parsed data (e.g. with JSON Schema) reduces risk. In distributed systems, JSON is often the common format for events, logs, and message queues, so consistent encoding and decoding across services is essential.

How to Calculate It

JSON value types (ECMA-404 §4)
Value typeSpec section
null4
boolean (true, false)4
number4
string4
array4
object4

Real-Life Example

A typical flow: your app calls fetch('/api/users'). The response body is a string of JSON. You run JSON.parse(responseBody) and get an array of user objects. You might then map over that array to render a list. If the API sends a trailing comma or a single-quoted key, JSON.parse throws and you have to fix the payload or ask the API owner to fix it. In another scenario, you might read a config file from disk, parse it as JSON, and use the result to configure the app at startup. If the file is malformed, failing fast with a clear parse error is better than continuing with invalid config. When sending JSON to an API, ensure the body is a string (e.g. JSON.stringify(payload)) and the Content-Type header is application/json so the server parses it correctly.

Common Mistakes

Trailing commas in objects or arrays (e.g. {"a": 1,}) make JSON invalid. Using single quotes for keys or strings is invalid. Unquoted keys are invalid. Comments aren’t part of the spec. Putting NaN or Infinity in numbers isn’t standard. Forgetting to escape double quotes inside a string breaks the parser. Copy-pasting from JavaScript object literals often introduces these issues.

Practical Tips

  • Validate JSON before committing configs or sending payloads.
  • Use a formatter (e.g. 2-space indent) in dev; minify for production if size matters.
  • Use JSON Schema or OpenAPI to document and validate API shapes.
  • Escape user input when building JSON strings; never eval() JSON.
  • Prefer UTF-8 for JSON on the wire and in files.
  • Use a reviver function in JSON.parse or a replacer in JSON.stringify when you need custom type handling.

FAQs

Conclusion

JSON is the default format for structured data on the web. Learn the syntax (double quotes, no trailing commas, valid escapes), validate early, and use schemas where it helps. That’s enough to use it confidently in APIs, configs, and storage. Keep payloads and config files valid and consistent across environments, and rely on standard parsers and serializers rather than string manipulation or eval.