--- 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).