SlideShare a Scribd company logo
DEVELOP
API
RP Ngoma College
IT Department
IT L7
Trainer: AnacletM/ranaclet2012@gmail.com
API OUTPUT
FORMATS
JSON & XML
3
JSON
JSON is a file format that uses human-readable text for storing and transmitting data
objects containing attribute-value pairs and arrays. JSON is used to store information in an
organized and easy-to-access manner.
JSON stands for JavaScript Object Notation. It offers a human-readable collection of data
that can be accessed logically.
JSON uses tags to mark up the data: "{"key": "value“, "o": another Value}." The keys and
values must always be surrounded by curly braces ({) and square brackets ([]),
respectively. In addition, each key-value pair must have an equal number of quotation
marks surrounding it - for example: {"name": "John"} would not be valid because there
are too few quotes after the name tag.
JSON is an ideal format for sharing information between web APIs and applications
because it's a simple way of serializing complex data into a single string
It is mainly used to store and exchange data between a server and a client.
4
JSON
5
Features of JSON
■ Easy to use – JSON API offers high-level facade, which helps you to simplify
commonly used use-cases.
■ Performance – JSON is quite fast as it consumes very less memory space, which is
especially suitable for large object graphs or systems.
■ Free tool – JSON library is open source and free to use.
■ Doesn’t require to create mapping – Jackson API provides default mapping for
many objects to be serialized.
■ Clean JSON – Creates clean, and compatible JSON result that is easy to read.
■ Dependency – JSON library does not require any other library for processing.
6
Features of JSON
1. Lightweight and Easy to Read
• Feature: JSON is a simple text format that is easy to read and write by both humans and
machines.
• Example:
• The structure is straightforward, making it easy to understand.
7
Features of JSON
4. Supports Nested Data Structures
• Feature: JSON allows you to nest objects within other objects, or include arrays to represent
more complex data structures.
• Example:
• You can represent complex relationships like nested addresses or lists of phone
numbers.
8
Features of JSON
5. Supports Arrays
• Feature: JSON supports arrays, which allow you to store multiple values in a single data
structure.
• Example:
This feature allows you to store multiple values in a single key (such as a list
of names).
9
Features of JSON
6. Human-Readable and Compact
Feature:
JSON (JavaScript Object Notation) is designed to be both compact and easy for humans to read.
It avoids unnecessary characters, making it lightweight and efficient for transmitting data
across networks.
■ Example:
Compared to XML, JSON uses a simpler syntax and takes up less space. For instance, JSON
doesn't require closing tags like XML, which helps keep the structure clean and easier to
understand. This smaller size also means faster data transfer and reduced bandwidth usage.
10
Features of JSON
7. Supports Different Data Types
• Feature: JSON supports various data types like strings, numbers, booleans, arrays, and objects.
This makes it versatile in representing different kinds of data.
• Example:
11
Features of JSON
8. Easily Parsed and Generated
•Feature: JSON can be easily parsed (converted into an object) and generated
(converted from an object to a string) in most programming languages.
•Example:
•In JavaScript, you can use JSON.parse() to convert a JSON string into an object and
JSON.stringify() to convert an object back into a JSON string.
12
Features of JSON
(REST)Representational State Transfer
(API)Application Programming Interface
is a web service that allows systems to
communicate over the HTTP protocol using a
set of rules (REST architectural style). It is
widely used to connect client and server
applications on the internet.
9. Easily Interoperable
•JSON is widely adopted for data exchange between different systems and programming languages,
especially in web services and APIs. Its simple text-based format makes it easy to parse, generate, and
interpret across various platforms.
Examples:
1.Web Applications (REST APIs):
JSON is used to send and receive data between a web browser (frontend) and a server
(backend).
Example: When you log in to a website, your username and password may be sent as:
13
Features of JSON
2. Mobile Apps:
Android and iOS apps use JSON to communicate with remote servers. For instance, a weather
app receives data like:
14
Features of JSON
3. IoT Devices:
Smart devices like thermostats or sensors send data in JSON format to central systems.
Example:
15
Features of JSON
4. Programming Languages Support:
JSON is natively supported or easily integrated in most languages like Python, JavaScript, Java,
C#, and PHP.
1. JavaScript (Native Support)
■ JavaScript can easily parse and stringify JSON using built-in methods.
16
Features of JSON
2. Python (Using json module)
17
Features of JSON
3. Java (Using org.json or Jackson Library)
18
Features of JSON
4. C# (.NET using Newtonsoft.Json or System.Text.Json)
19
Features of JSON
5. PHP (Using json_encode and json_decode)
20
Features of JSON
10. Flexible and Extensible
•Feature: JSON is flexible and can be extended to include new fields and values without breaking existing
systems.
•Example:
• You can easily add new attributes to the existing structure.
21
JSON Data format
■ Basic JSON Syntax
■ Here’s the basic structure:
22
JSON Data format
■ JSON syntax is derived from JavaScript object notation syntax:
■ JSON data is written as name/value pairs (aka key/value pairs). A name/value pair
consists of a field name (in double quotes), followed by a colon, followed by a
value:
Example: "name": "John"
■ The JSON format is almost identical to JavaScript objects. In JSON, keys must be strings, written
with double quotes: {"Key": "Value"}
✅ Data is in name/value pairs
✅ Double quotes " must be used around keys and string values
✅ Commas , separate key-value pairs
✅ Curly braces {} hold objects
✅ Square brackets [] hold arrays
23
JSON Data format
Example 1: Simple JSON Object
•"name" is the key and "Alice" is the value (string).
•"age" is the key and 25 is the value (number).
•"isStudent" is the key and true is the value (boolean).
24
JSON Data format
Example 2: Nested JSON Object
 The value of the key "employee" is another object.
 Inside "employee", "skills" is an array.
25
JSON Data format
Example 3: JSON Array
 This is a list of objects.
 Each object represents a person.
26
JSON Data Types
■ In JSON, values must be one of the following data types:
Note: JSON values cannot be one of the following data types:
• a function
• a date
• undefined
27
JSON Data Types
■ Details with Examples
2. Number
• No quotes for numbers.
• Can be integers or decimals (floating-point).
1. String
•Must be inside double quotes (").
•Can contain letters, numbers, and symbols.
28
JSON Data Types
3. Object
• A collection of key-value pairs.
• Each key must be a string.
• Values can be any JSON data type.
4. Array
• A list of items.
• Items are separated by commas.
• Items can be any JSON data type (strings, numbers, objects, arrays, booleans, or null).
29
JSON Data Types
5. Boolean
•Only two values: true or false (no quotes).
6. Null
•Represents no value.
30
XML
XML is an extensible markup language that is designed to store data. It is popularly
used for transferring data. It is case-sensitive, XML allows you to define markup
elements and generate customized markup language. An element is a basic unit in
the XML language. The extension of XML file is .xml
There are many benefits to using XML code. One of the biggest reasons is that it is
more flexible than HTML, which means you can easily create a custom markup
language for your website or application. In addition, this makes it easier to format
data and display it correctly in any browser or device.
XML also allows you to create custom tags that can be used in any XML data. These
tags are often used to define specific XML data. This makes it easier for developers
and designers to collaborate when creating new projects!
31
XML VS HTML
■ XML was designed to carry data - with focus on what data is
■ HTML was designed to display data - with focus on how data looks
■ XML tags are not predefined like HTML tags are
■ HTML works with predefined tags like <p>, <h1>, <table>, etc.
■ With XML, the author must define both the tags and the document structure. Example:
<part number="1976">
<name>Windscreen Wiper</name>
<description>The Windscreen wiper
automatically removes rain
from your windscreen, if it
should happen to splash there.
It has a rubber <ref part="1977">blade</ref>
which can be ordered separately
if you need to replace it.
</description>
</part>
32
XML VS HTML VS JSON
33
XML VS HTML VS JSON
34
XML VS HTML VS JSON
When to Use What?
• XML → Use when you need structured data with custom tags (e.g., document
storage, legacy systems).
• HTML → Use for designing and displaying content on websites.
• JSON → Use for lightweight and fast data exchange, especially in REST APIs and
web services.
35
Where to use XML
■ XML Separates Data from Presentation: XML does not carry any information
about how to be displayed, the same XML data can be used in many different
presentation scenarios. Because of this, with XML, there is a full separation
between data and presentation.
■ XML is Often a Complement to HTML: in many HTML applications, XML is used
to store or transport data, while HTML is used to format and display the same
data.
■ XML Separates Data from HTML: when displaying data in HTML, you should not
have to edit the HTML file when the data changes. With XML, the data can be
stored in separate XML files. With a few lines of JavaScript code, you can read
an XML file and update the data content of any HTML page.
36
XML Syntax
■ XML documents must contain one root element that is the parent of all other elements:
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Example:
<?xml version="1.0" encoding="UTF-8"?> (This line is called XML prolog)
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
 The XML prolog is optional. If it exists, it must come first in the document.
37
XML Syntax
■ Basic XML Structure:
3.Tags must be properly nested:
1. Start with an XML Declaration (optional but
recommended):
2.Every tag must have a closing tag:
38
XML Syntax
4.Tag names are case-sensitive:
5.Elements can have attributes:
6.You can use empty tags with self-closing syntax:
7.Special characters must be escaped:
39
XML Syntax (Cont’d)
■ All XML Elements Must Have a Closing Tag but the XML prolog does not have a closing tag! This
is not an error. The prolog is not a part of the XML document
■ XML Tags are Case Sensitive. The tag <Letter> is different from the tag <letter>
■ In XML, all elements must be properly nested within each other
■ XML elements can have attributes in name/value pairs just like in HTML. But in XML, the
attribute values must always be quoted:
<note date="12/11/2007">
<to>Peter</to>
<from>Jane</from>
</note>
■ There are 5 pre-defined entity references in XML:
&lt; < less than
&gt; > greater than
&amp; & ampersand
&apos; ' apostrophe
&quot; " quotation
mark
40
Difference between JSON and XML
Sample JSON File/Code
{
"student": [
{
"id":"01",
"name": "Tom",
"lastname": "Price"
},
{
"id":"02",
"name": "Nick",
"lastname": "Thameson"
}
]
}
Sample XML File/Code
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<student>
<id>01</id>
<name>Tom</name>
<lastname>Price</lastname>
</student>
<student>
<id>02</id>
<name>Nick</name>
<lastname>Thameson</lastname>
</student>
</root>
IT L7 - DEVELOP API 41
Advantages of using JSON
Here are the important benefits/ pros of using JSON:
■ Lightweight & Faster 🚀
JSON is smaller in size and faster to parse compared to XML.Ideal for APIs and web applications.
 Easy to Read & Write 👀
Uses a clean and simple structure (key-value pairs).Human-readable and easy for developers to
understand.
 Better Performance ⏩
JSON parsing is faster because it is directly supported by JavaScript (JSON.parse()).Consumes less
bandwidth.
 Easier to Work with in JavaScript 🔗
Since JSON is derived from JavaScript, it integrates seamlessly with JS-based applications.
 Supported by Most Modern Languages 🔧
Almost every programming language (Python, Java, PHP, etc.) has built-in support for JSON.
IT L7 - DEVELOP API 42
Disadvantages of using JSON
Here are cons/drawback of using JSON:
1.Limited Support for Metadata 📄
Unlike XML, JSON does not support attributes or schema definition.
2. No Support for Comments ❌
JSON does not allow inline comments, making documentation within the file difficult.
3.Less Secure 🔒
JSON can be vulnerable to security issues like JSON Hijacking if not handled properly.
IT L7 - DEVELOP API 43
Disadvantages of using JSON
📌 Example: XML with Metadata (using attributes)
In the above XML:id="101" and genre="fiction" are attributes — metadata describing the book.
❌ Equivalent JSON (no attributes, just key-value pairs)
IT L7 - DEVELOP API 44
Disadvantages of using JSON
❌ Invalid JSON Example with Comment (not allowed):
✅ This will throw a syntax error if parsed by a JSON parser because comments (e.g., // or /* */) are not allowed.
✅ Valid JSON (no comments):
45
Advantages of using XML
<person>
<name>John</name>
<age>30</age>
<city>New
York</city>
</person>
•Supports Metadata & Attributes️🏷️
•XML allows attributes (<person age="30">) that add
extra information to elements.
•Extensible & Self-Descriptive 📖
•XML is designed to store data with a clear structure and
meaning.
•Supports Comments 💬
•You can add comments (<!-- This is a comment -->) to
explain code.
•Schema Validation ✅
•XML can be validated using DTD or XSD schemas,
ensuring correct data structure.
•Better for Document Storage 📚
•Used in config files (e.g., Microsoft Office, Android
manifest) and data storage.
IT L7 - DEVELOP API 46
Advantages of using XML
Here are significant benefits/cons of using XML:
■ Makes documents transportable across systems and applications. With the help of XML,
you can exchange data quickly between different platforms.
■ XML separates the data from HTML
■ XML simplifies platform change process
■ Allows creating user-defined tags.
IT L7 - DEVELOP API 47
Disadvantages of using XML
Here, are cons/ drawbacks of using XML:
•Larger File Size 📂
•XML is verbose, requiring more storage and bandwidth.
•Slower Parsing ⏳
•XML parsing takes more time due to its complex structure.
•Complex Syntax 🤯
•More difficult to read and write than JSON.
•Not Ideal for Data Interchange 🔄
•APIs and modern applications prefer JSON due to performance issues with XML.

More Related Content

PDF
Json
PPTX
All about XML, JSON and related topics..
PPTX
JSON - (English)
PPTX
Introduction to JavaScript Object Notation(JSON)
PPTX
Json
All about XML, JSON and related topics..
JSON - (English)
Introduction to JavaScript Object Notation(JSON)

Similar to LU 1.3. JSON & XML.pptx about how they work and introduction (20)

PPT
Json – java script object notation
PPTX
Json
PPT
Json – java script object notation
PDF
Intro to JSON
PPT
json.ppt download for free for college project
PPT
PPTX
Json training
PPT
Java Script Object Notation (JSON)
PPTX
JSON.pptx
PPTX
Data exchange over internet (XML vs JSON)
PPTX
Intro to JSON
PDF
Basics of JSON (JavaScript Object Notation) with examples
PPTX
PDF
Introduction to JSON
PPTX
Web Development Course - AJAX & JSON by RSOLUTIONS
PPTX
Unit-2.pptx
PDF
JSON in JavaScript
PDF
JSON PRETTIFY.pdf
Json – java script object notation
Json
Json – java script object notation
Intro to JSON
json.ppt download for free for college project
Json training
Java Script Object Notation (JSON)
JSON.pptx
Data exchange over internet (XML vs JSON)
Intro to JSON
Basics of JSON (JavaScript Object Notation) with examples
Introduction to JSON
Web Development Course - AJAX & JSON by RSOLUTIONS
Unit-2.pptx
JSON in JavaScript
JSON PRETTIFY.pdf
Ad

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Institutional Correction lecture only . . .
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Computing-Curriculum for Schools in Ghana
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Sports Quiz easy sports quiz sports quiz
PDF
RMMM.pdf make it easy to upload and study
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Pre independence Education in Inndia.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Institutional Correction lecture only . . .
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Anesthesia in Laparoscopic Surgery in India
O5-L3 Freight Transport Ops (International) V1.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Microbial diseases, their pathogenesis and prophylaxis
2.FourierTransform-ShortQuestionswithAnswers.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
01-Introduction-to-Information-Management.pdf
Complications of Minimal Access Surgery at WLH
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Computing-Curriculum for Schools in Ghana
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Renaissance Architecture: A Journey from Faith to Humanism
Sports Quiz easy sports quiz sports quiz
RMMM.pdf make it easy to upload and study
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pre independence Education in Inndia.pdf
Ad

LU 1.3. JSON & XML.pptx about how they work and introduction

  • 1. DEVELOP API RP Ngoma College IT Department IT L7 Trainer: AnacletM/ranaclet2012@gmail.com
  • 3. 3 JSON JSON is a file format that uses human-readable text for storing and transmitting data objects containing attribute-value pairs and arrays. JSON is used to store information in an organized and easy-to-access manner. JSON stands for JavaScript Object Notation. It offers a human-readable collection of data that can be accessed logically. JSON uses tags to mark up the data: "{"key": "value“, "o": another Value}." The keys and values must always be surrounded by curly braces ({) and square brackets ([]), respectively. In addition, each key-value pair must have an equal number of quotation marks surrounding it - for example: {"name": "John"} would not be valid because there are too few quotes after the name tag. JSON is an ideal format for sharing information between web APIs and applications because it's a simple way of serializing complex data into a single string It is mainly used to store and exchange data between a server and a client.
  • 5. 5 Features of JSON ■ Easy to use – JSON API offers high-level facade, which helps you to simplify commonly used use-cases. ■ Performance – JSON is quite fast as it consumes very less memory space, which is especially suitable for large object graphs or systems. ■ Free tool – JSON library is open source and free to use. ■ Doesn’t require to create mapping – Jackson API provides default mapping for many objects to be serialized. ■ Clean JSON – Creates clean, and compatible JSON result that is easy to read. ■ Dependency – JSON library does not require any other library for processing.
  • 6. 6 Features of JSON 1. Lightweight and Easy to Read • Feature: JSON is a simple text format that is easy to read and write by both humans and machines. • Example: • The structure is straightforward, making it easy to understand.
  • 7. 7 Features of JSON 4. Supports Nested Data Structures • Feature: JSON allows you to nest objects within other objects, or include arrays to represent more complex data structures. • Example: • You can represent complex relationships like nested addresses or lists of phone numbers.
  • 8. 8 Features of JSON 5. Supports Arrays • Feature: JSON supports arrays, which allow you to store multiple values in a single data structure. • Example: This feature allows you to store multiple values in a single key (such as a list of names).
  • 9. 9 Features of JSON 6. Human-Readable and Compact Feature: JSON (JavaScript Object Notation) is designed to be both compact and easy for humans to read. It avoids unnecessary characters, making it lightweight and efficient for transmitting data across networks. ■ Example: Compared to XML, JSON uses a simpler syntax and takes up less space. For instance, JSON doesn't require closing tags like XML, which helps keep the structure clean and easier to understand. This smaller size also means faster data transfer and reduced bandwidth usage.
  • 10. 10 Features of JSON 7. Supports Different Data Types • Feature: JSON supports various data types like strings, numbers, booleans, arrays, and objects. This makes it versatile in representing different kinds of data. • Example:
  • 11. 11 Features of JSON 8. Easily Parsed and Generated •Feature: JSON can be easily parsed (converted into an object) and generated (converted from an object to a string) in most programming languages. •Example: •In JavaScript, you can use JSON.parse() to convert a JSON string into an object and JSON.stringify() to convert an object back into a JSON string.
  • 12. 12 Features of JSON (REST)Representational State Transfer (API)Application Programming Interface is a web service that allows systems to communicate over the HTTP protocol using a set of rules (REST architectural style). It is widely used to connect client and server applications on the internet. 9. Easily Interoperable •JSON is widely adopted for data exchange between different systems and programming languages, especially in web services and APIs. Its simple text-based format makes it easy to parse, generate, and interpret across various platforms. Examples: 1.Web Applications (REST APIs): JSON is used to send and receive data between a web browser (frontend) and a server (backend). Example: When you log in to a website, your username and password may be sent as:
  • 13. 13 Features of JSON 2. Mobile Apps: Android and iOS apps use JSON to communicate with remote servers. For instance, a weather app receives data like:
  • 14. 14 Features of JSON 3. IoT Devices: Smart devices like thermostats or sensors send data in JSON format to central systems. Example:
  • 15. 15 Features of JSON 4. Programming Languages Support: JSON is natively supported or easily integrated in most languages like Python, JavaScript, Java, C#, and PHP. 1. JavaScript (Native Support) ■ JavaScript can easily parse and stringify JSON using built-in methods.
  • 16. 16 Features of JSON 2. Python (Using json module)
  • 17. 17 Features of JSON 3. Java (Using org.json or Jackson Library)
  • 18. 18 Features of JSON 4. C# (.NET using Newtonsoft.Json or System.Text.Json)
  • 19. 19 Features of JSON 5. PHP (Using json_encode and json_decode)
  • 20. 20 Features of JSON 10. Flexible and Extensible •Feature: JSON is flexible and can be extended to include new fields and values without breaking existing systems. •Example: • You can easily add new attributes to the existing structure.
  • 21. 21 JSON Data format ■ Basic JSON Syntax ■ Here’s the basic structure:
  • 22. 22 JSON Data format ■ JSON syntax is derived from JavaScript object notation syntax: ■ JSON data is written as name/value pairs (aka key/value pairs). A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value: Example: "name": "John" ■ The JSON format is almost identical to JavaScript objects. In JSON, keys must be strings, written with double quotes: {"Key": "Value"} ✅ Data is in name/value pairs ✅ Double quotes " must be used around keys and string values ✅ Commas , separate key-value pairs ✅ Curly braces {} hold objects ✅ Square brackets [] hold arrays
  • 23. 23 JSON Data format Example 1: Simple JSON Object •"name" is the key and "Alice" is the value (string). •"age" is the key and 25 is the value (number). •"isStudent" is the key and true is the value (boolean).
  • 24. 24 JSON Data format Example 2: Nested JSON Object  The value of the key "employee" is another object.  Inside "employee", "skills" is an array.
  • 25. 25 JSON Data format Example 3: JSON Array  This is a list of objects.  Each object represents a person.
  • 26. 26 JSON Data Types ■ In JSON, values must be one of the following data types: Note: JSON values cannot be one of the following data types: • a function • a date • undefined
  • 27. 27 JSON Data Types ■ Details with Examples 2. Number • No quotes for numbers. • Can be integers or decimals (floating-point). 1. String •Must be inside double quotes ("). •Can contain letters, numbers, and symbols.
  • 28. 28 JSON Data Types 3. Object • A collection of key-value pairs. • Each key must be a string. • Values can be any JSON data type. 4. Array • A list of items. • Items are separated by commas. • Items can be any JSON data type (strings, numbers, objects, arrays, booleans, or null).
  • 29. 29 JSON Data Types 5. Boolean •Only two values: true or false (no quotes). 6. Null •Represents no value.
  • 30. 30 XML XML is an extensible markup language that is designed to store data. It is popularly used for transferring data. It is case-sensitive, XML allows you to define markup elements and generate customized markup language. An element is a basic unit in the XML language. The extension of XML file is .xml There are many benefits to using XML code. One of the biggest reasons is that it is more flexible than HTML, which means you can easily create a custom markup language for your website or application. In addition, this makes it easier to format data and display it correctly in any browser or device. XML also allows you to create custom tags that can be used in any XML data. These tags are often used to define specific XML data. This makes it easier for developers and designers to collaborate when creating new projects!
  • 31. 31 XML VS HTML ■ XML was designed to carry data - with focus on what data is ■ HTML was designed to display data - with focus on how data looks ■ XML tags are not predefined like HTML tags are ■ HTML works with predefined tags like <p>, <h1>, <table>, etc. ■ With XML, the author must define both the tags and the document structure. Example: <part number="1976"> <name>Windscreen Wiper</name> <description>The Windscreen wiper automatically removes rain from your windscreen, if it should happen to splash there. It has a rubber <ref part="1977">blade</ref> which can be ordered separately if you need to replace it. </description> </part>
  • 32. 32 XML VS HTML VS JSON
  • 33. 33 XML VS HTML VS JSON
  • 34. 34 XML VS HTML VS JSON When to Use What? • XML → Use when you need structured data with custom tags (e.g., document storage, legacy systems). • HTML → Use for designing and displaying content on websites. • JSON → Use for lightweight and fast data exchange, especially in REST APIs and web services.
  • 35. 35 Where to use XML ■ XML Separates Data from Presentation: XML does not carry any information about how to be displayed, the same XML data can be used in many different presentation scenarios. Because of this, with XML, there is a full separation between data and presentation. ■ XML is Often a Complement to HTML: in many HTML applications, XML is used to store or transport data, while HTML is used to format and display the same data. ■ XML Separates Data from HTML: when displaying data in HTML, you should not have to edit the HTML file when the data changes. With XML, the data can be stored in separate XML files. With a few lines of JavaScript code, you can read an XML file and update the data content of any HTML page.
  • 36. 36 XML Syntax ■ XML documents must contain one root element that is the parent of all other elements: <root> <child> <subchild>.....</subchild> </child> </root> Example: <?xml version="1.0" encoding="UTF-8"?> (This line is called XML prolog) <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>  The XML prolog is optional. If it exists, it must come first in the document.
  • 37. 37 XML Syntax ■ Basic XML Structure: 3.Tags must be properly nested: 1. Start with an XML Declaration (optional but recommended): 2.Every tag must have a closing tag:
  • 38. 38 XML Syntax 4.Tag names are case-sensitive: 5.Elements can have attributes: 6.You can use empty tags with self-closing syntax: 7.Special characters must be escaped:
  • 39. 39 XML Syntax (Cont’d) ■ All XML Elements Must Have a Closing Tag but the XML prolog does not have a closing tag! This is not an error. The prolog is not a part of the XML document ■ XML Tags are Case Sensitive. The tag <Letter> is different from the tag <letter> ■ In XML, all elements must be properly nested within each other ■ XML elements can have attributes in name/value pairs just like in HTML. But in XML, the attribute values must always be quoted: <note date="12/11/2007"> <to>Peter</to> <from>Jane</from> </note> ■ There are 5 pre-defined entity references in XML: &lt; < less than &gt; > greater than &amp; & ampersand &apos; ' apostrophe &quot; " quotation mark
  • 40. 40 Difference between JSON and XML Sample JSON File/Code { "student": [ { "id":"01", "name": "Tom", "lastname": "Price" }, { "id":"02", "name": "Nick", "lastname": "Thameson" } ] } Sample XML File/Code <?xml version="1.0" encoding="UTF-8" ?> <root> <student> <id>01</id> <name>Tom</name> <lastname>Price</lastname> </student> <student> <id>02</id> <name>Nick</name> <lastname>Thameson</lastname> </student> </root>
  • 41. IT L7 - DEVELOP API 41 Advantages of using JSON Here are the important benefits/ pros of using JSON: ■ Lightweight & Faster 🚀 JSON is smaller in size and faster to parse compared to XML.Ideal for APIs and web applications.  Easy to Read & Write 👀 Uses a clean and simple structure (key-value pairs).Human-readable and easy for developers to understand.  Better Performance ⏩ JSON parsing is faster because it is directly supported by JavaScript (JSON.parse()).Consumes less bandwidth.  Easier to Work with in JavaScript 🔗 Since JSON is derived from JavaScript, it integrates seamlessly with JS-based applications.  Supported by Most Modern Languages 🔧 Almost every programming language (Python, Java, PHP, etc.) has built-in support for JSON.
  • 42. IT L7 - DEVELOP API 42 Disadvantages of using JSON Here are cons/drawback of using JSON: 1.Limited Support for Metadata 📄 Unlike XML, JSON does not support attributes or schema definition. 2. No Support for Comments ❌ JSON does not allow inline comments, making documentation within the file difficult. 3.Less Secure 🔒 JSON can be vulnerable to security issues like JSON Hijacking if not handled properly.
  • 43. IT L7 - DEVELOP API 43 Disadvantages of using JSON 📌 Example: XML with Metadata (using attributes) In the above XML:id="101" and genre="fiction" are attributes — metadata describing the book. ❌ Equivalent JSON (no attributes, just key-value pairs)
  • 44. IT L7 - DEVELOP API 44 Disadvantages of using JSON ❌ Invalid JSON Example with Comment (not allowed): ✅ This will throw a syntax error if parsed by a JSON parser because comments (e.g., // or /* */) are not allowed. ✅ Valid JSON (no comments):
  • 45. 45 Advantages of using XML <person> <name>John</name> <age>30</age> <city>New York</city> </person> •Supports Metadata & Attributes️🏷️ •XML allows attributes (<person age="30">) that add extra information to elements. •Extensible & Self-Descriptive 📖 •XML is designed to store data with a clear structure and meaning. •Supports Comments 💬 •You can add comments (<!-- This is a comment -->) to explain code. •Schema Validation ✅ •XML can be validated using DTD or XSD schemas, ensuring correct data structure. •Better for Document Storage 📚 •Used in config files (e.g., Microsoft Office, Android manifest) and data storage.
  • 46. IT L7 - DEVELOP API 46 Advantages of using XML Here are significant benefits/cons of using XML: ■ Makes documents transportable across systems and applications. With the help of XML, you can exchange data quickly between different platforms. ■ XML separates the data from HTML ■ XML simplifies platform change process ■ Allows creating user-defined tags.
  • 47. IT L7 - DEVELOP API 47 Disadvantages of using XML Here, are cons/ drawbacks of using XML: •Larger File Size 📂 •XML is verbose, requiring more storage and bandwidth. •Slower Parsing ⏳ •XML parsing takes more time due to its complex structure. •Complex Syntax 🤯 •More difficult to read and write than JSON. •Not Ideal for Data Interchange 🔄 •APIs and modern applications prefer JSON due to performance issues with XML.