JSON or XML

Had a huge search on which is better JSON or XML for data interchange format, and conclusion was to use JSON

JSON vs XML: How JSON Is Superior To XML

Simplicity, Openness, & Interoperability

In terms of simplicity, openness, and interoperability, JSON and XML are tied. Sure, you’ll find people on both sides of each of these issues arguing for their favorite. However, when you strip away their opinions and dig down to the facts, there isn’t much difference between JSON and XML in terms of simplicity, openness, and interoperability.

Self-Describing Data & Internationalization

Another common trait that JSON and XML share is the implementation of self-describing data and internationalization. Both of these standards use Unicode standards and they both create data in a way the allows generic tools to manipulate the data. This makes these formats very easy to distribute to a wide range of users.

Extensibility

With JSON, you are limited to only storing classical data like text and numbers. However, XML allows you to store any data type you can come up with. The ability to extend the attributes of the data stored in XML files is what allows it to be more flexible than JSON. However, it also makes it more difficult to read. This makes XML more extensible, but that may not be a good thing. This depends on the type of information you are trying to transfer. Documents require extensibility to manage images, charts, graphs, and other elements of formatting. However, classical data does not require this extensibility and can benefit from the simplicity of JSON. This course about APIs covers the extensibility of XML and the use of JSON in much more detail.

Human Readable

Both XML and JSON files are said to be human readable. At least, they are understandable to programmers that work with these file formats. However, JSON files are more restrictive and therefore slightly more readable. This is because the number of data formats supported by JSON if much smaller than with XML. Additionally, the structure of the data is more standardized with JSON files due to the fact that there are fewer options when compared with XML formatting.

Complete Integration Of All Formats

With XML it is possible to attach any file of any format. On the other hand, JSON only supports traditional data formats. This means it is possible to include photos, audio, video, and other files within an XML file. While this may seem like a good thing at first, it can also be dangerous. That’s because you could also include an executable file which could have dangerous consequences to security. The simplicity of the data structures that JSON supports makes this exploit impossible using this format.

Sharing Traditional Data

JSON is the best tool for sharing data. This is because the data is stored in arrays and records while XML stores data in trees. Both have their advantages, but data transfers are much easier when the data is stored in a structure that is familiar to object-oriented languages. This makes it very easy to import data from a JSON file into Perl, Ruby, Javascript, Python, and many other languages. You can learn all about this from an online course about APIs. In order to do the same thing with XML, you would need to first transform the data before it can be imported. You can learn how by enrolling in a course about XML. For this reason, JSON is a superior file format for web APIs. You can learn about these benefits from a class that covers the basics of APIs.

Sharing Documents

When you want to share documents, XML is the right tool for the job. This is because it allows you to include data types like images, charts, and graphs. Additionally, XML offers options for transferring the structure, or format, of the data along with the actual data. JSON only offers options for transferring data without formatting, and only using traditional data formats. This makes XML the superior format for documents.

JSON: The Fat-Free Alternative to XML

Simplicity

XML is simpler than SGML, but JSON is much simpler than XML. JSON has a much smaller grammar and maps more directly onto the data structures used in modern programming languages.

Extensibility

JSON is not extensible because it does not need to be. JSON is not a document markup language, so it is not necessary to define new tags or attributes to represent data in it.

Interoperability

JSON has the same interoperability potential as XML.

Openness

JSON is at least as open as XML, perhaps more so because it is not in the center of corporate/political standardization struggles.

A common exchange format

JSON is a better data exchange format. XML is a better document exchange format. Use the right tool for the right job.

Many views of the one data

JSON does not provide any display capabilities because it is not a document markup language.

Self-Describing Data

XML and JSON have this in common.

Complete integration of all traditional databases and formats

(Statements about XML are sometimes given to a bit of hyperbole.) XML documents can contain any imaginable data type - from classical data like text and numbers, or multimedia objects such as sounds, to active formats like Java applets or ActiveX components.
JSON does not have a <[CDATA[]]> feature, so it is not well suited to act as a carrier of sounds or images or other large binary payloads. JSON is optimized for data. Besides, delivering executable programs in a data-interchange system could introduce dangerous security problems.

Internationalization

XML and JSON both use Unicode.

Open and extensible

XML’s one-of-a-kind open structure allows you to add other state-of-the-art elements when needed. This means that you can always adapt your system to embrace industry-specific vocabulary.

XML is human readable
JSON is much easier for human to read than XML. It is easier to write, too. It is also easier for machines to read and write

XML can be used as an exchange format to enable users to move their data between similar applications
The same is true for JSON.

XML provides a structure to data so that it is richer in information
The same is true for JSON.

XML is easily processed because the structure of the data is simple and standard
JSON is processed more easily because its structure is simpler.

There is a wide range of reusable software available to programmers to handle XML so they don't have to re-invent code JSON, being a simpler notation, needs much less specialized software. In the languages JavaScript and Python, the JSON notation is built into the programming language; no additional software is needed at all. In other languages, only a small amount of JSON-specific code is necessary. For example, a package of three simple classes that makes JSON available to Java is available for free from JSON.org.

XML separates the presentation of data from the structure of that data.

XML requires translating the structure of the data into a document structure. This mapping can be complicated. JSON structures are based on arrays and records. That is what data is made of. XML structures are based on elements (which can be nested), attributes (which cannot), raw content text, entities, DTDs, and other meta structures.

Those vocabularies can be automatically converted to JSON, making migration from XML to JSON very straightforward.

XML is easily readable by both humans and machines
JSON is easier to read for both humans and machines.

XML is object-oriented
Actually, XML is document-oriented. JSON is data-oriented. JSON can be mapped more easily to object-oriented systems.

XML is being widely adopted by the computer industry
JSON is just beginning to become known. Its simplicity and the ease of converting XML to JSON makes JSON ultimately more adoptable.

The new FACEBOOK graph api always returns data in json.
XML has an overhead on communication size and processing required for parsing so it's being dropped from web API's.

 

So, For creating web services with REST server & JSON output so that it can be used for the mobile app of the drupal website :

Services are collections of methods available to remote applications..

  1. Modules required to install..
    • Chaos tools
    • Services
    • Libraries
    • REST server
    • OAuth
    • OAuth authentication
  2. Clean URLs is needed to be enabled.. (Not must but better if enabled).. check 'For CLEAN URLs issue' in this file for further steps needed if facing issues..
  3. Add service in /admin/structure/services
  4. Added service can be edited at : /admin/structure/services/list/test_service_name
    • Machine-readable name of the endpoint
    • Select 'REST' as the server that should be used to handle requests to this endpoint.
    • Give Path to endpoint.. this would be the one used while calling the webservices...
    • In SERVER tab of edit webservice, select 'json' as 'Response formatters' and 'application/json' as 'Request parsing'
    • In RESOURCES tab of edit webservice, Select the resource(s) or methods you would like to enable..
      it could be one for each webservice, like user login for login webservice etc.
  5. Finally, if you have drupal setup under 'drupal-webservices' then your URL will be http://localhost/drupal-webservices/test_service_name/node/1.json

Google has provided a basic REST Client...
On https://chrome.google.com/webstore/ search for 'Postman - REST Client' under Developer Tools

Add new comment