JSON Vs XML - Both are used to store and transfer data between server and client. Both are humanly machine-readable and language-independent.
JSON stands for Javascript object notation. It is a text-based data format that is used to store and transfer data from server to client and vice versa
JSON is derived from Javascript but it could be used by different languages such as Python, Ruby, PHP, and Java too. Therefore JSON is called language independent.
The JSON file can be saved as a .json
file extension while it can be defined either in string format(inside of quotes) or object within other files.
JSON can be represented either in object format or array format. Let us see each of them.
JSON object is written inside the curly braces {}
.JSON object consists of key/value pairs such as {key:value}
.Key-value must be placed inside the double quote as a string while the value can be put inside double quote incase of string otherwise do not put value inside double quote.
{
"name": "smith", "salary": 500000,"age":32,"job":"ui/ux"
}
JSON array written inside the square bracket like javascript array.
Source Code
<script type="text/javascript">
// JSON array
[ "apple", "mango", "banana"]
</script>
Code Explanation
XML stands for Extensible Markup Language and it is also used to store and transfer data from server to client or browser and from client to server. It is used by different programming languages and it is again human and machine-readable.
Please keep in mind that XML is very similar to JSON but XML can take longer text and more time to read and write hence it also takes much to parse.
XML can be parsed with the help of an XML parser while JSON can ve parsed with the help of the javascript standard function.
<employees>
<employee>
<username>Smith</username> <Job>Designetr</Job>
</employee>
<employee>
<username>John Doe</username>
<location>Developer</location>
</employee>
</employees>