Theory
એક record, બે costumes
સમાન Garba Night, બંને રીતે dressed:
<event>
<name>Garba Night</name>
<seats>350</seats>
</event>
{ "name": "Garba Night", "seats": 350 }
Same facts, same nesting, visibly different weight. "Compare JSON and XML" એ આ paper ના most reliably asked questions માંનું એક છે, અને તે BOTH halves ને wants કરે છે: શું 2 formats share કરે છે, અને ક્યાં તેઓ part થાય છે.
Theory
similarities (અડધો ભાગ જે students forget કરે છે)
બંને formats છે:
- self-describing: names data સાથે travel કરે છે (
seats, tagged અથવા quoted) - hierarchical: values values ની અંદર nest થાય છે, tree-shaped
- plain text: humans અને દરેક platform દ્વારા readable
- language-independent: parsers everywhere exist કરે છે
- AJAX-compatible: Unit 4 નું XMLHttpRequest બંને ને equal ease સાથે fetch કરે છે
Exam craft: compare question similarities paragraph ને પણ scores કરે છે; ફક્ત differences ને writing કરવું તે marks ને forfeit કરે છે.
At a glance
differences (rows તરીકે learn કરો)
| Aspect | XML | JSON |
|---|---|---|
| End tags | દરેક element closes થાય છે: </name> | કોઈ નહીં: braces અને brackets |
| Size | same data માટે Heavier | Lighter, less bandwidth |
| Arrays | કોઈ native arrays નહીં: elements ને repeat કરો | Native: [ ... ] |
| Parsing in JS | DOM માં, પછી તેને walk કરો | એક JSON.parse ready objects માં |
| Extras | Attributes, namespaces, comments | ફક્ત data: તેમાંથી કોઈ નહીં |
| Validation | DTD/schema standards | Schema tooling exists, less central |
Practical
આખો fest, બંને રીતે (ceremony ને count કરો)
<!-- XML: 2 events -->
<events>
<event id="1">
<name>Garba Night</name>
<seats>350</seats>
</event>
<event id="2">
<name>Coding Contest</name>
<seats>60</seats>
</event>
</events>
// JSON: the same 2 events
{
"events": [
{ "id": 1, "name": "Garba Night", "seats": 350 },
{ "id": 2, "name": "Coding Contest", "seats": 60 }
]
}
This example runs in Gri-Learn on the web, where you can edit it and see the output.
Quiz
FestConnect ના app ને events ની LIST ને ordered collection તરીકે જોઈએ છે જે તે indexes સાથે loop કરી શકે. કયો format difference અહીં most matters કરે છે?
- JSON strings double quotes ને use કરે છે જ્યારે XML text ને કોઈ જોઈએ નથી
- JSON પાસે native arrays છે; XML એ list ને repeated <event> elements તરીકે represent કરવું પડે છે
- XML case-sensitive છે જ્યારે JSON નથી
- JSON files હંમેશા 1 KB થી નાના હોય છે
Show the answer
JSON પાસે native arrays છે; XML એ list ને repeated <event> elements તરીકે represent કરવું પડે છે
ordered, indexable list એ exactly શું JSON ના [ ] native આપે છે: parsing પછી, data.events[1] એ second event છે, અને દરેક loop જે તમે જાણો છો તે apply થાય છે. XML same idea ને ફક્ત convention દ્વારા express કરે છે (several sibling <event> elements), જેને consuming code એ gather અને order કરવું પડે છે itself. Option A true છે પણ અહીં cosmetic છે. Option C અડધું-invented છે: JSON string comparisons પણ case-sensitive છે; case rules એ XML ની Unit 1 story હતી. Option D tendency (lighter) ને fake guarantee માં turn કરે છે. difference ને NEED સાથે match કરો: એ રીતે comparison marks earn થાય છે.
Think first
તો શા માટે XML હજુ exist કરે છે?
જો JSON lighter છે, array-native અને parse-friendly, તો શા માટે XML vanish નથી થયું? તમારા OWN coursework માંથી 2 domains ને name કરો જ્યાં XML હજુ right અથવા required tool છે, tap કરતા પહેલાં.
Show the answer
Android (BCA305-02): દરેક layout અને manifest એ XML છે, attributes અને namespaces પર lean કરે છે (android:layout_width), જે JSON simply lacks કરે છે. Established document standards: RSS feeds, SVG graphics, office documents: ecosystems built on XML ના document features અને schema validation પર, કોઈ migration sight માં નથી. XML પણ comments અને mixed text-plus-markup ને gracefully carry કરે છે: તે DOCUMENT format છે જે data ને hold કરી શકે છે; JSON DATA format છે, full stop. exam-worthy conclusion: APIs અને JS apps માટે JSON; જ્યાં attributes, namespaces, validation અથવા standards rule કરે ત્યાં XML: tools, rivals નહીં.
Watch out
Comparison-answer traps
"JSON એ XML ને replace કર્યું": overstatement; તેને web APIs સુધી scope કરો અને તમે accurate છો.
"XML એ programming language છે": કોઈ format કંઈ compute નથી કરતું; બંને data/markup notations છે.
comments ને JSON સાથેAttributing કરવા: XML પાસે <!-- --> છે; JSON પાસે કંઈ નથી (તેના પર whole lesson soon). આ row ને swap કરવું એ favourite trick option છે.
similarities half ને Forgetting કરવું: self-describing, hierarchical, text, language-independent: તેમને first કહો, પછી differ.
Theory
એક record, બંને costumes ને hold કરો
આજના Garba Night pair (XML block અને JSON line) ને memorised રાખો તમારા portable exam exhibit તરીકે: બંને ને memory થી writing અને differences પર pointing એ compare-JSON-and-XML નો full answer છે, worked example included. અહીંથી unit JSON ના own grammar પર deep જાય છે: objects with strings and numbers next, પછી 5 array forms, પછી curious case comments નો જે JSON refuse કરે છે.
Summary
Key takeaways
- Similarities first: બંને self-describing, hierarchical, plain text, language-independent, AJAX-fetchable.
- JSON: કોઈ end tags નહીં, lighter, native arrays, JS objects માં one-step parse.
- XML: attributes, namespaces, comments, schema validation: document-format strengths.
- JSON = data format; XML = document format જે data ને carry કરી શકે છે.
- web APIs અને JS apps માટે JSON પસંદ કરો; જ્યાં standards (RSS, SVG, Android) અથવા attributes rule કરે ત્યાં XML.
- બંને costumes માં same record એ perfect exam exhibit છે: pair ને learn કરો.
- Memory hook: JSON light travels કરે છે, XML luggage carry કરે છે જે તેને ક્યારેક truly needs હોય છે.