Table of Contents |
---|
Key Points
...
Reference_description_with_linked_URLs_________________________ | Notes_________________________________________________________________ |
---|---|
Key Concepts
Data Representation - JSON vs XML
JSON vs XML in 2023: Comparing Features and Examples
https://hackr.io/blog/json-vs-xml
Feature | XML | JSON |
Language | XML is a markup language, not a programming language, that has tags to define elements. | JSON is just a format written in JavaScript. |
Data Storage | XML data is stored as a tree structure. Example:
| Data is stored like a map with key value pairs. Example:
|
Processing | Can perform processing, and formatting documents and objects | Does not do any processing or computation |
Speed | Bulky and slow in parsing, leading to slower data transmission | Very fast as the size of file is considerably small, faster parsing by the JavaScript engine and hence faster transfer of data |
Namespaces Support | Supports namespaces, comments and metadata | There is no provision for namespace, adding comments or writing metadata |
Document Size | Document size is bulky and with big files, the tag structure makes it huge and complex to read. | Compact and easy to read, no redundant or empty tags or data, making the file look simple. |
Array Support | Doesn’t directly support arrays. To be able to use an array, one has to add tags for each item. | Supports array |
Data Types Support | Supports many complex data types including charts, images, and other non-primitive data types. | JSON supports only strings, numbers, arrays, Booleans, and objects. Objects can only contain primitive types. |
UTF Support | XML supports UTF-8 and UTF-16 encodings. | JSON supports UTF as well as ASCII encodings. |
Security | XML structures are prone to some attacks as external entity expansion and DTD validation are enabled by default. When these are disabled, XML parsers are safer. | JSON parsing is safe almost all the time except if JSONP is used, which can lead to Cross-Site Request Forgery (CSRF) attack. |
Data Processing | Though the X in AJAX stands for XML, because of the tags in XML, a lot of bandwidth is unnecessarily consumed, making AJAX requests slow. | As data is serially processed in JSON, using it with AJAX ensures faster processing and is hence preferable. Data can be easily manipulated using the eval() method |
XML or JSON - which is best?
XML (Extensible Markup Language) has been around for more than 3 decades now and it is an integral part of every web application. Whether a configuration file, mapping document, or schema definition, XML made life easier for data interchange by giving a clear structure to data and helping in dynamic configuration and loading of variables.
JSON stores all of its data in a map format (key/value pairs) that is neat and easier to comprehend. People cite the ease of data modeling or mapping directly to domain objects as the main advantage of JSON over XML — which makes it more predictable and easy to understand the structure. Bear in mind that not everyone agrees with this.
For starters, JSON is just a data format whereas XML is a markup language. You can actually place a query and get your answer through XPath. Similarly, metadata, attributes, and namespaces can be added in XML. Further, XML along with XSL, XSD, XQuery, etc. makes for a powerful combination. These are some important features that still make XML a worthy choice.
In any case, if a project requires document markup and metadata information, it is better to use XML. Otherwise, for a more organized data interchange, JSON could be your preferred choice.
Differences Between JSON and XML
https://aws.amazon.com/compare/the-difference-between-json-xml/
JSON is an open data interchange format that is readable by both people and machines. JSON is independent of any programming language and is a common API output in a wide variety of applications. XML is a markup language that provides rules to define any data. It uses tags to differentiate between data attributes and the actual data. While both formats are used in data exchange, JSON is the newer, more flexible, and more popular option.
Where to JSON or XML?
Both formats work for data exchange
for performance > JSON
for complex data representation of custom data types > XML
Potential Value Opportunities
...