How do I compare two JSON requests
JSON, XML and YAML in comparison
For Web APIs and configurations, XML is increasingly being replaced by simpler formats such as JSON and YAML. For example, Twitter has discontinued its support for XML in its streaming APIs. This article compares JSON, YAML and XML and shows the strengths of the formats for certain areas of application.
The usual separation of data (e.g. XML documents) and code (e.g. Java) is thus avoided. Even the Lisp language from the pioneering days of EDP made no difference between code and data. The use of JSON for the asynchronous transfer of data between servers and websites is particularly popular. JSON has now almost replaced XML as AJAX format.
You will find the corresponding YAML and XML documents for the same order in the following sections.
The strengths of JSON lie in a clear notation, low overhead and good support from a large number of programming languages.
YAML is the short form of "YAML Ain't Markup Language". YAML became known as a format for configuring Ruby on Rails. In contrast to XML, the language for data exchange is easy to read and edit. This was achieved by eliminating brackets, quotation marks and tags. YAML uses indentations to represent hierarchical structures. This makes the order in Listing 2 even more compact and clear than the order in JSON format.
In the example we find a list of positions (items). As in word processing, a list is created by placing a bullet in front of it.
Since YAML is a superset of JSON, brackets can optionally be used to achieve JSON compatibility.
YAML is line-oriented and can therefore also be processed by tools such as awk or grep.
In addition, YAML offers some features that cannot be found in JSON and XML. For example, in Listing 3, a Map cities1 defined with capitals. The map cities2 extends the first map to Rome and corrects the entry for Germany.
YAML also supports data types and type casting.
Since the release of the XML 1.0 specification, XML has spread widely. There are thousands of markup languages based on XML. XML has penetrated almost all areas of application. However, there is one area that continues to resist the dominance of XML. Although XML was created to solve problems in web design, there is a strong dislike for it. For example, Firefox and IE namespace declarations in XML documents simply filter out rather than display them.
Listing 4 shows the order already known from above in XML format.
The order in XML format has a higher overhead and is more confusing than the JSON or YAML document. If we left our comparison at that, XML would be the clear loser. In contrast to JSON and YAML, XML is a markup language. XML can therefore be used for more than just serializing objects.
In Listing 5, the same order was provided with additional XML features. Elements from other XML languages are now used in the document. The id Element points to a REST resource via XLink, which can be used to request representations of the order. The address has been included and the description of the second position now contains HTML markup.
The short example also shows how horrible XML documents can be. If you were to add namespaces to JSON or YAML, these would probably become just as confusing.
The structure of XML documents can be described with XML schema. Listing 6 shows an excerpt from a schema with the definition of a type for an item in an order.
The format description with XML schema offers numerous possibilities:
- With the help of the schema, XML editors can recognize and display errors or offer auto-completion
- Code for the serialization of XML documents can be generated from XML schema
- The scheme can serve as documentation
- XML documents can be validated against the schema.
The following list contains just a few examples:
- Queries with XPath and XQuery
- Transformation with XSLT
- Storage in an XML database
- Routing via an ESB
By using namespaces, elements and attributes in XML can be uniquely named worldwide. An XML document can be interpreted separately from an application. With JSON and YAML documents, the content only makes sense through the application that reads the document.
The namespaces give XML documents a context in which they can be interpreted. XML advocates therefore accuse other formats of provinciality.
With XML, the REST idea that everything is a resource can be easily implemented.
A reference to a resource can be added to any information via an XLink attribute or an enclosing element. This is not possible with JSON or YAML, although they pretend to be “web” languages.
JSON has challenged XML's sole rule and shown that it can be used for special tasks such as B. the serialization of objects is a leaner alternative. JSON and YAML also show that readability can be improved. XML still scores with its versatility, tool support and the large number of standards that are based on XML or can be combined with XML.
Introduction to JSON
YAML Ain’t Markup Language (YAML ™) Version 1.2
Extensible Markup Language (XML) 1.0 (Fifth Edition)
- Actually do catchy phrases to achieve goals
- What are your top 10 favorite countries
- How many districts are there in Madhya Pradesh
- Is Frantastique worth the somewhat high cost
- Which president was murdered by Charles Guiteau
- What function does Microsoft OneNote fulfill
- Why wasn't the Palm Pre more successful
- Homeschooling just can't be a school
- Why is propositional logic important
- The federal courts make laws
- Which is India's Best Spoken English Institute
- Are there dental universities in Myanmar
- What is the importance of fertilizers
- Which is better Instagram Snapchat or Twitter
- Blood cells need oxygen
- Buy the Tesla Cybertruck
- Depressed people cannot eat or do anything
- How can I improve my website UX
- What is IPv4
- There are wild American quarter horses
- Is related to Bruce Lee to Stan Lee
- When does college become irrelevant
- Where do the oceans get their salt from?
- Which companies own which Marvel characters