---
id: json-vs-xml
title: "JSON vs XML"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["JSON vs XML", "JSON XML comparison", "JSON or XML", "data format comparison", "XML alternative"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.88
created_at: 2026-06-23
updated_at: 2026-06-23
review_reason: ""
merge_history: []
tags: ["javascript", "js", "web", "frontend", "w3schools", "json", "xml"]
raw_sources: ["https://www.w3schools.com/js/js_json_xml.asp"]
applied_in: []
github_commit: ""
---
# [[JSON vs XML]]
## π― ν μ€ ν΅μ°° (One-line insight)
JSON and XML are both self-describing, hierarchical, language-portable data formats, but JSON is shorter, uses no end tags, supports arrays, and can be parsed by a standard JavaScript function into a ready-to-use object β whereas XML needs an XML parser. [S1]
## π§ ν΅μ¬ κ°λ
(Core concepts)
- **Both formats serve the same role** β representing the same hierarchical data (e.g. an `employees` list) in text. [S1]
- **JSON is like XML** β both are self-describing (human readable), both are hierarchical (values within values), both can be parsed and used by lots of programming languages, and both can be fetched with an `XMLHttpRequest`. [S1]
- **JSON is unlike XML** β JSON doesn't use end tags, JSON is shorter, JSON is quicker to read and write, and JSON can use arrays. [S1]
- **Parsing is the key difference** β XML has to be parsed with an XML parser; JSON can be parsed by a standard JavaScript function. [S1]
- **Why JSON is better than XML** β XML is much more difficult to parse than JSON; JSON is parsed into a ready-to-use JavaScript object. [S1]
## π§© μΆμΆλ ν¨ν΄ (Extracted patterns)
- **Same data, two encodings** β compare the JSON array-of-objects against the equivalent nested XML element tree. [S1]
- **Parse-to-object pattern (JSON)** β fetch a JSON string, then `JSON.parse` it. [S1]
- **Parse-and-walk pattern (XML)** β fetch an XML document, loop through it with the XML DOM, extract values, and store them in variables. [S1]
## π μΈλΆ λ΄μ© (Details)
The following examples both define an employees object/structure with 3 employees. [S1]
**JSON example:** [S1]
```json
{"employees":[
{ "firstName":"John", "lastName":"Doe" },
{ "firstName":"Anna", "lastName":"Smith" },
{ "firstName":"Peter", "lastName":"Jones" }
]}
```
**XML example:** [S1]
```xml
John Doe
Anna Smith
Peter Jones
```
**JSON is like XML because** [S1]
- Both JSON and XML are "self describing" (human readable).
- Both JSON and XML are hierarchical (values within values).
- Both JSON and XML can be parsed and used by lots of programming languages.
- Both JSON and XML can be fetched with an `XMLHttpRequest`.
**JSON is unlike XML because** [S1]
- JSON doesn't use end tag.
- JSON is shorter.
- JSON is quicker to read and write.
- JSON can use arrays.
The biggest difference is: XML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript function. [S1]
**Why JSON is better than XML**
XML is much more difficult to parse than JSON. JSON is parsed into a ready-to-use JavaScript object. [S1]
Using XML: fetch an XML document, use the XML DOM to loop through the document, extract values and store them in variables. [S1]
Using JSON: fetch a JSON string, then `JSON.Parse` the JSON string. [S1]
## π οΈ μ μ© μ¬λ‘ (Applied in summary)
The page contrasts two real workflows: the XML path (fetch document β walk the XML DOM β extract into variables) versus the JSON path (fetch string β `JSON.parse`). No external project/commit applications found in the source.
## π» μ½λ ν¨ν΄ (Code patterns)
The JSON encoding of the comparison data set:
```json
{"employees":[
{ "firstName":"John", "lastName":"Doe" },
{ "firstName":"Anna", "lastName":"Smith" },
{ "firstName":"Peter", "lastName":"Jones" }
]}
```
The equivalent XML encoding:
```xml
John Doe
```
## βοΈ λΉκ΅ λ° μ ν κΈ°μ€ (Comparison & decision criteria)
JSON vs XML, per the source: [S1]
- **Similarities** β both self-describing/human readable, hierarchical, multi-language parseable, and fetchable via `XMLHttpRequest`.
- **JSON advantages** β no end tags, shorter, quicker to read and write, supports arrays, and parses directly into a ready-to-use JavaScript object with a standard JS function.
- **XML cost** β must be parsed with an XML parser, then walked via the XML DOM to extract values into variables β "much more difficult to parse than JSON."
- **Decision** β the page recommends JSON because it is parsed into a ready-to-use JavaScript object, making it the lower-effort choice for JavaScript-driven web pages.
## βοΈ λͺ¨μ λ° μ
λ°μ΄νΈ (Contradictions & updates)
No contradictions found in the source.
## β
κ²μ¦ μν λ° μ λ’°λ
- **μν:** draft
- **κ²μ¦ λ¨κ³:** conceptual (μ€μ μ μ© μ¬λ‘ λ°κ²¬ μ applied/validatedλ‘ μΉκ²© κ°λ₯)
- **μΆμ² μ λ’°λ:** B (W3Schools β widely used educational reference, not a primary standards body)
- **μ λ’° μ μ:** 0.88
- **μ€λ³΅ κ²μ¬ κ²°κ³Ό:** μ κ· μμ± (New discovery)
## π μ§μ κ·Έλν (Knowledge Graph)
- **μμ/루νΈ:** [[JavaScript Tutorial]]
- **κ΄λ ¨ κ°λ
:** [[JavaScript JSON]], [[JavaScript JSON Syntax]], [[JavaScript JSON Parse]], [[JavaScript JSON Arrays]]
- **μ°Έμ‘° λ§₯λ½:** Referenced when choosing a data interchange format for a web application or API.
## π μΆμ² (Sources)
- [S1] W3Schools β JSON vs XML β https://www.w3schools.com/js/js_json_xml.asp
## π λ³κ²½ μ΄λ ₯ (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "JSON vs XML" page (Astra wiki-curation, P-Reinforce v3.1 format).