JSON | Structure, Data Types, Conversion & XML Evolution
JSON
JavaScript Object Notation
Structure | Data Types & Conversion | Technological Advancement from XML
Lightweight Language-Agnostic Web Standard
Human & Machine Readable Supported in 50+ Languages Used by 95%+ of Web APIs
1. What Is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based, language-independent data
interchange format. Originally derived from JavaScript object literal syntax, JSON has grown far
beyond its origins to become the universal language of data exchange across virtually every
programming ecosystem, platform, and industry.
JSON was formally specified by Douglas Crockford in the early 2000s and standardized as
ECMA-404 and RFC 8259. Its design philosophy centers on simplicity: a minimal set of rules
that both humans can read effortlessly and machines can parse with exceptional speed.
Official Standard
JSON is defined by two specifications: ECMA-404 (The JSON Data Interchange Standard) and
RFC 8259 (Internet Engineering Task Force). Both describe the same format and are
maintained to ensure universal, cross-platform compatibility.
2. JSON Structure
JSON is built on two universal data structures that exist in virtually every modern programming
language, making it an ideal common ground for data exchange.
2.1 The Two Root Structures
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
Object { } Array [ ]
An unordered collection of zero or more An ordered sequence of zero or more values.
name/value pairs (also called properties or Values are separated by commas and enclosed
members). Each name is a string, followed by in square brackets. Array elements can be of any
a colon, followed by a value. Pairs are JSON type and can be mixed within the same
separated by commas. Objects are enclosed in array.
curly braces.
2.2 Basic JSON Structure Example
{
"id": 1001,
"name": "Ayesha Malik",
"email": "ayesha@[Link]",
"isActive": true,
"score": 98.5,
"tags": ["developer", "full-stack", "mentor"],
"address": {
"city": "Lahore",
"country": "Pakistan",
"postalCode": "54000"
},
"projects": null
}
2.3 Structural Rules
JSON has strict, unambiguous syntax rules that must be followed precisely:
• Keys must always be strings enclosed in double quotes — single quotes are not valid
JSON
• Key-value pairs inside objects are separated by commas; the last pair must NOT have a
trailing comma
• Array elements are separated by commas; trailing commas are forbidden
• JSON is case-sensitive: 'Name', 'name', and 'NAME' are three distinct keys
• Strings must use double quotes — special characters must be escaped with a backslash
• Whitespace (spaces, tabs, newlines) outside of strings is ignored and used only for
readability
• A JSON document must have exactly one root value — either an object or an array
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
2.4 Nested & Complex Structures
JSON supports arbitrary nesting — objects can contain arrays, arrays can contain objects, and
these can be nested to any depth, enabling representation of complex hierarchical data.
{
"company": "TechCorp Ltd",
"founded": 2015,
"departments": [
{
"name": "Engineering",
"headcount": 45,
"teams": ["Frontend", "Backend", "DevOps", "QA"]
},
{
"name": "Product",
"headcount": 12,
"teams": ["Design", "Research", "Strategy"]
}
],
"publiclyTraded": false,
"ceo": null
}
3. JSON Data Types
JSON defines exactly six data types. This minimal, precise set of types is one of JSON's
greatest strengths — it maps naturally to data structures in nearly every programming language,
making parsing and serialization straightforward.
3.1 The Six JSON Data Types
Type Syntax Example Description
String "double quotes" "Hello, World!" Unicode text, must use
escape sequences for
special chars
Number integer or float 42, 3.14, -7, 1.5e10 No distinction between
int/float; no NaN or Infinity
allowed
Boolean true or false true, false Lowercase only; True or
False are invalid
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
Null null null Represents absence of
value; lowercase only
Object { key: value, ... } {"x": 1, "y": 2} Unordered collection of
name/value pairs
Array [ value, ... ] [1, "two", true, null] Ordered list; elements can
be mixed types
3.2 String Type — Deep Dive
Strings are the most commonly used JSON type and require careful handling of special
characters through escape sequences.
{
"simple": "Hello World",
"withQuote": "He said \"JSON is great\"",
"withSlash": "C:\\Users\\Documents",
"newline": "Line 1\nLine 2",
"tab": "Column1\tColumn2",
"unicode": "\u0041 is the letter A",
"emoji": "Status: \uD83D\uDE80 Deployed"
}
Common escape sequences: \" (double quote), \\ (backslash), \n (newline), \t (tab), \r
(carriage return), \uXXXX (Unicode).
3.3 Number Type — Deep Dive
JSON uses a single Number type for all numeric values. There is no separate integer, float, or
long type. This simplicity comes with important constraints.
{
"integer": 42,
"negative": -17,
"float": 3.14159,
"scientific": 1.5e10,
"negSci": 2.7E-4,
"invalid_nan": NaN, // NOT valid JSON
"invalid_inf": Infinity, // NOT valid JSON
"invalid_hex": 0xFF, // NOT valid JSON
"invalid_oct": 077 // NOT valid JSON
}
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
3.4 Type Comparison Across Languages
JSON Type JavaScript Python Java Go
String String str String string
Number Number int / float int / double int / float64
Boolean Boolean bool boolean bool
Null null None null nil
Object Object / Map dict Map / POJO map / struct
Array Array list List / array slice
4. Data Conversion
Data conversion refers to the process of transforming JSON data into native programming
language structures (parsing/deserialization) and the reverse — converting native structures
back into JSON text (serialization/stringification). This bidirectional conversion is the foundation
of all API communication.
4.1 Serialization vs Deserialization
Serialization (Encoding) Deserialization (Decoding)
Converting a native data structure (object, dict, Converting a JSON string into a native data
struct) into a JSON string. Also called: stringify, structure. Also called: parse, unmarshal, decode,
marshal, encode, dump. Example: sending load. Example: receiving data FROM an API
data TO an API endpoint or saving to a file. response and working with it in code.
4.2 JSON Conversion in JavaScript
// --- PARSE: JSON string → JavaScript object ---
const jsonString = '{"name":"Ali","age":28,"skills":["JS","React"]}';
const obj = [Link](jsonString);
[Link]([Link]); // "Ali"
[Link]([Link][0]); // "JS"
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
// --- STRINGIFY: JavaScript object → JSON string ---
const user = { name: 'Sara', active: true, score: 95.5 };
const json = [Link](user);
// Result: '{"name":"Sara","active":true,"score":95.5}'
// Pretty-printed (indented) output
const pretty = [Link](user, null, 2);
/* Result:
{
"name": "Sara",
"active": true,
"score": 95.5
}
*/
4.3 JSON Conversion in Python
import json
# --- PARSE: JSON string → Python dict ---
json_str = '{"city":"Karachi","pop":15000000,"coastal":true}'
data = [Link](json_str)
print(data["city"]) # "Karachi"
print(type(data)) # <class 'dict'>
# --- DUMP: Python dict → JSON string ---
person = {"name": "Fatima", "age": 30, "languages": ["Urdu", "English"]}
json_output = [Link](person, indent=2)
# --- FILE I/O ---
with open('[Link]', 'w') as f:
[Link](person, f, indent=2) # Write to file
with open('[Link]', 'r') as f:
loaded = [Link](f) # Read from file
4.4 JSON Conversion in Other Languages
// --- JAVA (using Jackson library) ---
ObjectMapper mapper = new ObjectMapper();
String json = [Link](myObject); // Serialize
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
MyClass obj = [Link](json, [Link]); // Deserialize
// --- Go (standard library) ---
jsonBytes, _ := [Link](myStruct) // Serialize
[Link](jsonBytes, &myStruct) // Deserialize
// --- PHP ---
$obj = json_decode($jsonString, true); // Deserialize (true = assoc array)
$str = json_encode($phpArray); // Serialize
// --- C# (.NET) ---
var obj = [Link]<MyClass>(jsonString);
var str = [Link](myObject);
4.5 Common Conversion Pitfalls
Type Precision Warning
JSON Numbers have no integer/float distinction and are limited by IEEE 754 double-precision
floating point. Integers larger than 2^53 - 1 (9,007,199,254,740,991) cannot be precisely
represented. For large IDs (e.g., Twitter/X IDs), always use strings instead of numbers.
• Date/Time has no JSON type — use ISO 8601 strings ("2024-04-27T10:30:00Z") and
parse on both ends
• undefined in JavaScript is NOT valid JSON and is silently dropped during
[Link]()
• Circular references (objects referencing themselves) cause [Link]() to throw an
error
• Special float values NaN and Infinity are not valid JSON — replace with null or string
representation
• Key order is NOT guaranteed in JSON objects — never rely on property order for logic
• Deep nesting can cause stack overflows during parsing — some parsers enforce nesting
depth limits
5. Technological Advancement: From XML to JSON
The shift from XML (Extensible Markup Language) to JSON represents one of the most
significant transitions in web technology history. Understanding this evolution reveals not just a
change in file format, but a fundamental shift in how developers think about data exchange, API
design, and web architecture.
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
5.1 The Era of XML (1990s – 2000s)
XML emerged from the Standard Generalized Markup Language (SGML) and became a W3C
recommendation in 1998. It was designed to be self-describing, extensible, and universally
structured — a single format that could represent any data, any document, any configuration.
XML in its Prime
From roughly 1998 to 2010, XML was the dominant data interchange format. Technologies like
SOAP (Simple Object Access Protocol), WSDL (Web Services Description Language), XSLT,
and RSS were built entirely on XML. Enterprise systems, government platforms, and B2B
integrations standardized on XML-based web services.
A typical XML representation of a user record:
<?xml version="1.0" encoding="UTF-8"?>
<user>
<id>1001</id>
<name>Ayesha Malik</name>
<email>ayesha@[Link]</email>
<isActive>true</isActive>
<tags>
<tag>developer</tag>
<tag>full-stack</tag>
</tags>
<address>
<city>Lahore</city>
<country>Pakistan</country>
</address>
</user>
5.2 The Rise of JSON (2001 – Present)
Douglas Crockford popularized JSON in 2001, recognizing that JavaScript's native object literal
syntax could serve as a simple, powerful data format. The [Link] website he created
became a widely referenced specification before formal standardization.
The same user record in JSON:
{
"id": 1001,
"name": "Ayesha Malik",
"email": "ayesha@[Link]",
"isActive": true,
"tags": ["developer", "full-stack"],
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
"address": {
"city": "Lahore",
"country": "Pakistan"
}
}
The contrast is immediately evident: the JSON version contains the same information in roughly
half the characters, with no closing tags, no XML declaration, and no namespace complexity.
5.3 XML vs JSON — Comprehensive Comparison
Dimension XML JSON
Verbosity Highly verbose — every value Concise — key-value pairs with
requires opening and closing tags minimal syntax overhead
Readability Readable but cluttered with Clean, minimal, and intuitive for
repetitive markup tags humans to read and write
Data Types Everything is text — types must be 6 native types: string, number,
enforced by schema (XSD) boolean, null, object, array
Parsing Speed Slower — complex tree-based Faster — simple tokenizer;
DOM or SAX event parsing [Link]() is highly optimized
required
Payload Size Large — 30-50% overhead from Small — minimal syntax;
redundant tag pairs compresses extremely well with
gzip
Comments Supports <!-- comments --> No comment syntax — intentionally
natively excluded from spec
Namespace Support Built-in namespace support via No namespaces — simplicity by
xmlns prefix declarations design
Schema Validation Mature schemas: DTD, XSD, JSON Schema (draft standard),
RELAX NG for strict validation Joi, Zod, Ajv for validation
Metadata/Attributes First-class attribute support within No attribute concept — metadata
tags stored as regular keys
Browser Support Native via DOMParser / Native via [Link]() /
XMLHttpRequest [Link]() in all browsers
Streaming SAX parser enables event-driven JSON streaming via NDJSON
streaming (Newline Delimited JSON)
Primary Use Cases Documents, configs, legacy REST APIs, web apps, config files,
enterprise, SOAP services NoSQL databases
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
5.4 Timeline of the XML-to-JSON Transition
Year Milestone
1998 W3C publishes the XML 1.0 specification. XML becomes the backbone of enterprise
web services.
1999 SOAP protocol introduced, using XML as its message format. Becomes dominant in
B2B integration.
2001 Douglas Crockford coins the term 'JSON' and registers [Link]. First formal
description of the format.
2004 Ajax (Asynchronous JavaScript and XML) popularized by Google Maps. Ironically,
JSON soon replaces XML in Ajax.
2006 JSON begins appearing in REST APIs. Twitter, Flickr, and other Web 2.0 platforms
offer JSON responses.
2009 [Link] released — JavaScript on the server. JSON becomes the natural data format
for full-stack JS development.
2013 ECMA-404 officially standardizes JSON. GitHub API, Stripe, Twilio, and most new
APIs ship JSON-first.
2014 MongoDB (JSON/BSON documents) reaches version 2.6. NoSQL databases
accelerate JSON adoption for storage.
2017 RFC 8259 supersedes RFC 4627 with a cleaner, stricter JSON specification.
2018 GraphQL (JSON-based) gains mainstream adoption. REST + JSON remains
dominant; XML largely relegated to legacy.
2020s JSON is the default. YAML (JSON superset for configs), JSON5, NDJSON, and
JSON-LD extend the ecosystem.
5.5 Why JSON Won
The transition from XML to JSON was not accidental — it was driven by concrete technical and
economic pressures:
• The Rise of JavaScript: With browsers running JS natively, a format identical to JS
object literals eliminated a parsing step entirely
• Mobile & Bandwidth Constraints: Early smartphones had limited data — JSON's smaller
payloads meant real cost savings
• REST Architecture: Roy Fielding's REST principles matched JSON's simplicity; together
they created the modern web API economy
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
• Developer Experience: Junior developers could read and write JSON immediately; XML
required learning namespaces, schemas, and DTDs
• Performance: Benchmarks consistently show JSON parsing 2-3x faster than equivalent
XML in most environments
• NoSQL Database Alignment: MongoDB, CouchDB, Elasticsearch, and Firebase store
data as JSON documents natively
• Tool Ecosystem: Every language, framework, and platform provides first-class JSON
support out of the box
5.6 When XML Still Makes Sense
JSON has won the web API wars, but XML remains the right choice in specific, important
contexts:
• Document formats: Microsoft Office (DOCX, XLSX), OpenDocument Format (ODF) are
XML-based
• Configuration: Maven ([Link]), Spring, Ant, and many Java frameworks use XML for
configuration
• SOAP-based legacy systems: Banks, healthcare (HL7 FHIR partially), and government
systems maintain SOAP/XML
• SVG graphics: Scalable Vector Graphics is XML-based and integral to web design
• RSS/Atom feeds: Widely used XML formats for content syndication
• When metadata and attributes are important: XML attributes allow richer self-description
without separate keys
5.7 The JSON Ecosystem Today
JSON's success has spawned an entire family of related standards and tools:
JSON Extensions JSON Schema
JSON5 adds comments and trailing commas. A vocabulary for annotating and validating JSON
NDJSON (Newline Delimited) enables documents. Libraries like Ajv, Joi, and Zod allow
streaming large datasets line by line. JSON-LD declaring required fields, types, formats, and
adds linked data semantics for semantic web constraints — bringing XML Schema-level rigor
applications. to JSON.
JSON in Databases JSON in APIs
PostgreSQL supports JSONB (binary JSON) REST APIs universally return JSON. GraphQL
columns with indexing. MySQL 5.7+ has native uses JSON for responses. OpenAPI 3.0
JSON type. MongoDB stores BSON (Binary describes APIs using JSON Schema. JSON:API
JSON). Redis stores JSON via the RedisJSON is a specification for RESTful JSON API
module. conventions and relationships.
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
6. JSON Best Practices
Writing effective JSON goes beyond valid syntax. These best practices ensure your JSON is
secure, maintainable, performant, and interoperable across systems.
6.1 Naming & Structure
• Use camelCase for key names in web APIs (firstName, not first_name or FirstName)
• Be consistent with naming conventions — do not mix camelCase, snake_case, and
PascalCase
• Prefer specific, descriptive key names — avoid single-letter or ambiguous abbreviations
• Use null explicitly for missing values rather than omitting the key — improves schema
clarity
• Design flat structures where possible; excessive nesting harms readability and parsing
performance
6.2 Security
• Never trust incoming JSON — always validate against a schema (Ajv, Joi, Zod) before
processing
• Sanitize string values to prevent stored XSS attacks when rendering JSON data in
HTML
• Do not use eval() to parse JSON — always use [Link]() which is safe and
sandboxed
• Limit maximum payload size on APIs to prevent JSON bomb (deeply nested / very large)
DoS attacks
• Avoid including sensitive data (passwords, secrets, PII) in JSON logs or error responses
6.3 Performance
• Enable gzip/Brotli compression for JSON API responses — typically reduces payload by
70-80%
• Use pagination for large collections — never return unbounded arrays from APIs
• Consider binary formats (MessagePack, CBOR, Protobuf) when JSON parsing becomes
a bottleneck
• Cache parsed JSON objects rather than re-parsing the same response multiple times
• Use streaming JSON parsers (NDJSON) for very large datasets rather than loading all
into memory
JSON Technical Reference Guide April 2026
JSON | Structure, Data Types, Conversion & XML Evolution
7. Conclusion
JSON: The Universal Language of Data
JSON's triumph over XML is a masterclass in how simplicity, pragmatism, and alignment with
developer workflows can reshape an entire industry. It succeeded not because it was
theoretically superior in all dimensions, but because it was good enough in the right ways —
easy to read, easy to write, fast to parse, and perfectly matched to the web platform that
JavaScript built. Understanding JSON deeply — its structure, type system, conversion
semantics, and historical context — is foundational knowledge for every developer working in
the modern software ecosystem.
Key takeaways from this guide:
• JSON is defined by 6 types and 2 structures — master these and you master the format
• Serialization and deserialization are core operations in every API-connected application
• The XML-to-JSON transition was driven by the web, mobile, JavaScript, and REST —
not theory
• JSON's ecosystem continues to grow with Schema validation, NDJSON, JSON-LD, and
database-native support
• XML is not dead — it remains essential in documents, enterprise systems, and specific
standards
• Best practices around naming, security, and performance turn valid JSON into
professional JSON
"The art of programming is the art of organizing complexity."
JSON is the simplest tool we have for doing exactly that.
JSON Technical Reference Guide April 2026