JSON (JavaScript Object Notation)

botond published 2025. 07. 14., h - 20:18 time

Content

 

Overview

In modern IT, whether it's about communicating web services, configuring servers, or storing data, a common language that different systems understand is essential. This role is now filled by JSON, As the JavaScript Object Notation abbreviation. It is a lightweight, text-based standard designed specifically for exchanging and storing data.

The biggest advantage of JSON lies in its duality: its structure is so simple and logical that easily readable by the human eye and editable, but also extremely fast and easy for computers to process (parse). It is basically built from key-value pairs and ordered lists (arrays), which is very similar to how most programming languages ​​handle data in memory.

Although its name refers to the JavaScript language – as it originally comes from its object description syntax – it is important to note that JSON is now completely language-independent It has become a standard. It is natively supported by virtually every modern programming environment, from C++ to Python and PHP to Go. In this article, we will examine the history of JSON, its exact syntax, the specific standards based on it (such as JSON-RPC or JSON-Schema), and its practical uses for Linux system administrators.

 

 

history

The history of JSON dates back to the early 2000s. Although the format technically already existed as part of the JavaScript language, it was developed as a stand-alone data exchange standard. Douglas crockford was defined and popularized around 2001. The goal was to create a text-based format that would enable real-time, stateless communication between servers and web browsers (later called AJAX technology) without the need for Flash plug-ins or Java applets.

Initially, the standard was unofficial, with only a single-page website (json.org) describing its operation. However, its simplicity was such an overwhelming success that it soon became a de facto standard and was later officially standardized (first by RFC 4627, then the current one ECMA-404 and RFC 8259 documents). Interestingly, although it originated from JavaScript, today we are talking about two separate entities, and the syntax of JSON is stricter than that of JavaScript objects in some respects (e.g. in the use of quotation marks).

The XML vs. JSON switch

Before the advent of JSON, the world of data exchange was dominated by XML (Extensible Markup Language). XML is a very robust, but extremely verbose language. All data had to be enclosed in opening and closing tags (e.g. <nev>Kovács János</nev>), which significantly increased file size and network traffic. In addition, processing (parsing) XML in browsers and on servers was a computationally intensive task.

JSON, on the other hand, offered a "lightweight" alternative. It describes the same data in a much more concise way ("nev": "Kovács János"), eliminating unnecessary repetitions. Since its structure is identical to the internal data structures of programming languages, its processing is almost trivial and lightning fast. This difference in efficiency has led to modern web APIs (REST, GraphQL) and microservices using JSON almost exclusively, while XML has been relegated to the realm of more specialized, enterprise systems (e.g. SOAP).

 

Syntax and data types

JSON has a very clean syntax, consisting of just a few rules. The data is hierarchically structured, relying on two basic structures: a collection of name-value pairs (objects) and an ordered list of values ​​(arrays). The format is strictly textual, and uses UTF-8 encoding by default.

Structure: Key-value pairs

The basic building block of JSON data is key: value (key:value) pair. These pairs make up the Objects (Objects) enclosed in curly brackets { } they will be involved.

A very important rule that distinguishes JSON from plain JavaScript objects: the key (name) must always be in quotes!

Example of a simple object:

{
  "nev": "LinuxPortal",
  "alapitas_eve": 2018,
  "aktiv": true
}

As shown in the example, the key (e.g. "nev") and the value (e.g. "LinuxPortal") are separated by a colon, and pairs are separated by a comma.

Common mistake: The trailing comma

One of the strictest rules of JSON syntax is that no comma after the last element! While modern programming languages ​​(PHP, JS, Python) often overlook this, a standard JSON parser immediately throws an error (SyntaxError) if we "forget" a comma at the end of the list.

Supported data types

JSON values ​​(the part after the colon) can only be of one of the following six types. It is important to note that, for example, Date or Function types do not exist in the standard.

  • String: A Unicode character string enclosed in quotation marks. Special characters (e.g., quotation marks, line breaks) are represented by backslashes (\must be escaped with a ) character.
    Example: "Ez egy szöveg\nÚj sorral"
  • Number: Integer or floating point number. JSON does not distinguish between the two at the storage level. It cannot NaN vagy Infinity, only a specific numerical value.
    Example: 42, 3.14, -10
  • Boolean (Logical): It has two possible values: true (true) or false (false). Must be written in all lowercase.
  • Zero: An empty value, or a value that is missing. Also in lowercase: null.
  • Array: Ordered list of values, square brackets [ ] The elements of the array can be of any valid JSON type, even mixed types.
    Example: ["alma", 123, true]
  • Object: Embedded JSON object. This allows for the description of complex, tree-structured data models.
    Example: "cím": { "város": "Budapest", "irsz": 1011 }

 

 

The JSON "family" and its extensions

JSON itself is extremely flexible, but this flexibility can sometimes be a disadvantage: it has no built-in rules, type checking, or semantic reporting. To remedy this, many standards have been built on JSON over the years, solving specific problems.

JSON Schema: A validation tool

Because JSON is schema-less, an API cannot be sure whether the client has sent correctly formatted data (e.g. whether the "age" field is actually a number and not negative). The json schema is a standard that describes the expected structure of other JSON data in JSON format.

It is like a blueprint or a contract: it defines required fields, data types, number ranges, or string formats (e.g. email address validation). It is essential in modern API development because it allows for automatic validation of incoming data without the need for complex if-else we should write conditions in the code.

JSON-RPC: Remote Procedure Call

A JSON-RPC (Remote Procedure Call) is a stateless, lightweight protocol that defines how to request a remote server to execute a specific function (procedure) using JSON messages. Its structure is very simple: we send a request that contains the name of the method (e.g. subtract), the parameters (e.g. [42, 23]) and an identifier.

This protocol is one of the basic pillars of communication in modern systems. For example, the protocol discussed in our previous encyclopedia entry is based on it. MCP (Model Context Protocol) but it is also used by cryptocurrency wallets and many microservices. Its advantage is that it is independent of the transport layer: it works over HTTP, WebSocket, or even a simple TCP/IP connection.

JSON-LD: Semantic Data (Linked Data)

While plain JSON only stores data (e.g. "nev": "Gulyásleves"), the machine does not know whether it is a recipe for a dish, a person's name, or a product. The JSON-LD (Linked Data) aims to give meaning (semantics) to data.

This technology is SEO (search engine optimization) basis. When we see a recipe appear in Google search with an image, rating and preparation time (Rich Snippets), it is because the website is in the background in JSON-LD format, the Schema.org "explained" the content of the page to the search engine using its dictionary. The key is @context and @type using fields that define the context in which the data is interpreted.

JWT: JSON Web Token

A JWT is an open standard (RFC 7519) designed for secure, compact transmission of information between two parties. It is most commonly used for authentication in modern web applications. When we log in to a site, the server returns a digitally signed token containing our permissions (e.g. user ID, role) in JSON format.

Important safety warning

The content (Payload) of JWT tokens is only is encoded (Base64Url), not encrypted! This means that anyone who obtains the token can read the data inside it. Therefore, never put sensitive information (e.g. password, bank card details) inside the JWT unless you use special encryption (JWE).

JSONP: The historical solution (before CORS)

A JSONP (JSON with Padding) is a now largely obsolete but historically important technique used to overcome browser security limitations, the so-called Same-Origin Policy(the principle of the same origin) was invented to circumvent.

A modern CORS (Cross-Origin Resource Sharing) Before the standard, web scripts (AJAX) could not retrieve data from other domains. JSONP overcame this limitation with a trick: JSON data was not retrieved in raw form, but wrapped in a JavaScript function call (this is "padding"), and was retrieved from a <script> via the <script> tag – because the browser did not prohibit the loading of scripts. For example, instead of the server sending back {"id": 1}, he sent: callbackFuggveny({"id": 1});Although the method worked, it carried serious security risks (since it ran uncontrolled foreign code in the browser), so the more secure CORS standard is now used almost everywhere instead.

 

JSON in the Linux world

Although Linux traditionally uses line-based, plain text configuration files (such as .ini, .conf Or the /etc files under .js), with the rise of modern software and cloud-native technologies, JSON has become an unavoidable factor in server operations as well.

Configuration files and structured logs

Many modern services and development tools use JSON format to store their settings. It is essential in web development. composer.json (PHP) or package.json In addition to Node.js, we often encounter it at the system administrator level: for example, the configuration of the Docker daemon (/etc/docker/daemon.json) or the outputs of modern cloud providers' command line tools (AWS CLI, Azure CLI) also use this.

The other critical area is structured logging (structured logging). The problem with traditional, line-based log files (e.g. syslog) is that they are difficult to process programmatically (requiring complex regular expressions). In contrast, if an application logs in JSON format (e.g. {"level": "error", "time": "...", "msg": "Connection failed"}), log analysis systems (like the ELK stack or Grafana Loki) can read the fields immediately, indexably, allowing for precise searching and filtering.

jq: The command line processor

The only downside to JSON in the Linux terminal is that it doesn't work with traditional text processing tools (grep, awk, sed) have a hard time dealing with it, especially if the data is broken into multiple rows or deeply nested. This is the problem that the jq, which is the "Swiss Army Knife of JSONs".

A jq is a lightweight, flexible command-line tool for filtering, formatting, and transforming JSON data. With it, you can extract a value from a huge configuration file or pretty-print a compressed, one-line API response with a single command. Anyone working with JSON data on Linux today will find it useful. jq knowledge is just as fundamental as ls or the cd of commands.

 

 

Advantages and disadvantages

Like any technology, JSON has its strengths and weaknesses. It is important to be aware of these characteristics to choose the right tool.

Advantages

  • Human readability: The greatest strength of JSON is its simplicity. A well-formed file can be read and edited by anyone with a simple text editor, without the need for specialized tools.
  • Universal support: There is virtually no modern programming language or framework that does not natively support writing and reading JSON, making it the most compatible data exchange format between different systems.
  • Structure: Unlike CSV, it is capable of storing hierarchical, nested data (tree structures), while being much more compact and clean than XML.
  • Web integration: Because it originates from JavaScript, it is the "natural" data format for web browsers and JavaScript-based technologies (Node.js), allowing for extremely fast processing.

Disadvantages

  • Lack of comments: The standard JSON (RFC 8259) does not support commentsThis is a serious drawback in configuration files, as we cannot write explanations for each setting, nor can we temporarily "comment out" lines. (Extensions like JSONC or JSON5 try to overcome this problem, but they are not part of the official standard).
  • Verbosity: Although more compact than XML, JSON can be wasteful compared to binary formats (such as Protocol Buffers or MessagePack), as it requires rewriting key names (e.g., "id": 1, "id": 2...). For large amounts of data, this can consume significant bandwidth.
  • Type limitations: It is missing important data types such as Date (which is usually stored as a string) or the distinction between integer and floating point numbers, which can lead to inaccuracies in some systems.

 

Resources, Related Content: