JSON: what it is, data structure and working principle

Author: IT Sectr Published: 2026-03-08 Reading time: 8 min

JSON (JavaScript Object Notation) — is a text-based data interchange format based on JavaScript object syntax. It is used everywhere: from REST APIs and configuration files to data storage in databases and mobile applications. According to the official JSON website, the format is language-independent and supported by virtually all modern platforms. JSON has become the de facto standard for data transfer between client and server.

Key Takeaways

  • JSON — a lightweight text format for structured data based on JavaScript syntax
  • Six data types — string, number, boolean, null, array and object for any structures
  • Universality — supported by all programming languages and platforms
  • REST API — the main format for data exchange in web and mobile applications
  • Human readability — simple syntax is easy to read and edit without tools

What is JSON?

JSON is a text format for representing structured data, based on JavaScript syntax. Despite its origins in JavaScript, the format is completely language-independent — parsers and serializers exist for all popular programming languages.

The history of JSON began in the early 2000s, when Douglas Crockford extracted a subset of JavaScript syntax for data exchange. In 2013, the format was standardized as ECMA-404, and later as ISO/IEC 21778:2017. The name stands for JavaScript Object Notation.

The main advantage of JSON is its minimalistic syntax. Only six types are used to describe data: string, number, boolean, null, array and object. This is sufficient for representing any data structures used in applications.

Where JSON is Used

  • REST API — the main format for requests and responses between server and client
  • Configuration files — package.json, tsconfig.json, .prettierrc
  • Databases — MongoDB, PostgreSQL (JSONB), Firebase Firestore
  • Mobile applications — storing settings, data caching
  • Web technologies — WebSocket, Server-Sent Events, localStorage

JSON Syntax and Data Types

JSON syntax is extremely simple: data is represented as key-value pairs, where the key is a string in double quotes, and the value is one of six basic types. Objects are enclosed in curly braces, arrays in square brackets. Strings must use double quotes; single quotes are not allowed.

Numbers in JSON can be integers or floating-point, positive or negative, with exponential notation. Boolean values are represented by the literals true and false, and the absence of a value by null. Arrays contain an ordered set of values of any type, including nested arrays and objects.

json
{
  "name": "JSON",
  "type": "text",
  "version": 2024,
  "flexible": true,
  "extensions": null,
  "languages": [
    "JavaScript",
    "Python",
    "Java"
  ],
  "nested": {
    "info": "nested support"
  }
}
Type Example Description
String “text” In double quotes, with escape sequences
Number 42 Integer, floating-point, exponential
Boolean true true or false — without quotes
null null Absence of value
Object {} Unordered set of key-value pairs
Array [] Ordered list of values

JSON in REST API

JSON is the primary data interchange format for REST APIs in mobile and web development. The server sends JSON in the response body, the client in the request body. The standard Content-Type header for JSON is application/json.

Modern REST APIs use JSON to transmit all types of data: from simple lists to complex nested structures with relationships between entities. Client libraries (such as Axios in JavaScript or Retrofit on Android) automatically serialize and deserialize JSON, freeing the developer from manual parsing.

An important advantage of JSON in REST APIs is the ability for partial data transfer (partial response) via query parameters, as well as support for nested resources without additional requests to the server.

Parsing JSON on Mobile Platforms

JSON parsing on mobile platforms is performed using built-in tools. Android uses Gson from Google or Moshi from Square, iOS uses the Codable protocol with JSONDecoder. Each platform provides convenient tools for converting JSON to native objects and back.

JSON on Android (Kotlin)

On Android, the popular approach uses Gson or Moshi. Simply define a data class with @SerializedName annotations and call fromJson for deserialization. The library automatically maps JSON field names to class properties.

kotlin
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName

data class User(
    @SerializedName("id") val id: Int,
    @SerializedName("name") val name: String,
    @SerializedName("email") val email: String
)

fun parseJson(jsonString: String): User {
    val gson = Gson()
    return gson.fromJson(jsonString, User::class.java)
}

JSON on iOS (Swift)

On iOS, the built-in Codable protocol with JSONDecoder is used. The data structure is declared as a struct conforming to Codable, after which JSON is parsed with a single line. JSONEncoder performs reverse serialization — converting an object to JSON for sending to the server.

swift
import Foundation

struct User: Codable {
    let id: Int
    let name: String
    let email: String
}

func parseJSON(from data: Data) throws -> User {
    let decoder = JSONDecoder()
    return try decoder.decode(User.self, from: data)
}

JSON vs XML: Format Comparison

JSON and XML are the two main formats for transmitting structured data. JSON wins in simplicity and performance, XML in rigor and validation. The choice between them depends on project requirements: REST APIs more often use JSON, complex documents with schemas use XML.

XML requires closing tags for every element, increasing data size by 2-3 times compared to JSON. At the same time, XML supports namespaces, XSD schemas, attributes, and XSLT transformation, making it more powerful for document management and enterprise system integration tasks.

Characteristic JSON XML
Syntax Minimalistic, key-value Tag-based, opening and closing tags
Data size Compact 2-3 times larger than JSON
Data types Six basic types Text only, types via schemas
Validation No built-in, via JSON Schema XSD — strict and mature
Namespaces None Full namespace support
Parsing speed High Lower due to complexity

JSON Working Examples

Examples demonstrate typical JSON operations in mobile development: parsing API responses, creating JSON for sending, and processing nested structures. Understanding these patterns is essential for any mobile application developer.

Serializing an Object to JSON

In JavaScript, JSON.stringify converts an object to a JSON string. The second argument can be an array of keys for selective serialization or a replacer function. The third argument sets indentation for formatting.

typescript
interface Order {
  id: string;
  items: OrderItem[];
  total: number;
  createdAt: string;
}

const order: Order = {
  id: 'ord_001',
  items: [{ product: 'phone', quantity: 2 }],
  total: 1599.98,
  createdAt: '2026-07-03T10:00:00Z'
};

const jsonString = JSON.stringify(order, null, 2);

Parsing Nested JSON

In Kotlin with the Moshi library, nested JSON objects are handled through nested data classes. The @Json annotation specifies the JSON field name if it differs from the class property name. Arrays are represented as List with the element type.

kotlin
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory

data class ApiResponse(
    val status: String,
    val data: List<Product>,
    val pagination: Pagination
)

data class Product(
    val id: Int,
    val title: String,
    val price: Double
)

data class Pagination(
    val page: Int,
    val total: Int
)

val moshi = Moshi.Builder()
    .add(KotlinJsonAdapterFactory())
    .build()

JSON Schema: Structure Validation

JSON Schema is a language for describing the structure of a JSON document, similar to XSD for XML. Using JSON Schema, you can specify required fields, data types, value ranges, string patterns, and nested structure. Schema validation detects data errors before they are processed in the application.

JSON Schema is widely used in OpenAPI (Swagger) for documenting REST APIs, in input data validation forms, and in testing. The schema file itself is a JSON document, allowing standard JSON parsers to read it. Online validators and libraries exist for all popular programming languages.

In mobile development, JSON Schema is used for validating server responses during testing and for checking configuration files. Libraries like network-validator on Android and json-schema-validator allow embedding validation directly into the development process, preventing errors at early stages.

Frequently Asked Questions

What data types does JSON support?

JSON supports six types: string (in double quotes), number (integer and floating-point), boolean (true/false), null, object (key-value pairs in {}) and array (list of values in []). This is sufficient for any data structures in applications.

Can comments be used in JSON?

No, the JSON standard does not support comments. If you need comments, use JSON5 (extended JSON) or add a description field, for example “_comment”: “explanation”. Some tools, like VS Code, support comments in configuration JSON files, but this is a non-standard extension.

How is JSON different from JSONB in PostgreSQL?

JSONB is a binary storage format for JSON in PostgreSQL. Unlike text JSON, JSONB is faster to process, supports indexing (GIN indexes), and guarantees key uniqueness. However, JSONB takes up more disk space due to added metadata.

How to check if JSON is valid?

Use JSONLint (jsonlint.com) for quick validation, the built-in JSON.parse() in JavaScript with try-catch, or IDE plugins. Validation includes checking correct quotes, bracket closure, and type conformance. For complex schemas, use JSON Schema Validator.

What is the maximum JSON file size?

There is no limit in the JSON specification. In practice, the size is limited by device memory and parser capabilities. For mobile applications, it is recommended not to exceed 1-2 MB per response, and for large data use pagination or streaming.

Summary

  • JSON — a minimalistic text format with six data types for exchanging structured information
  • Language independence — JSON parsers exist for all popular programming languages
  • REST API uses JSON as the standard format for requests and responses in mobile applications
  • Parsing is performed using built-in tools: Gson/Moshi on Android, Codable on iOS
  • JSON is 2-3 times more compact than XML, but inferior to Protobuf in performance
  • Human readability — syntax is easy to read and debug without special tools
  • JSON Schema — an additional tool for validating structure and data types

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also