We help IT Professionals succeed at work.

json vs xml

gudii9 asked
what are differences between json and xml. what are advantages, disadvantages of each

I read like below
JSON uses typed objects. All XML values are typeless strings and must be parsed at runtime
what it mean by typed object and typeless strings and runtime parsing

please advise
Watch Question

Both are text based human readable formats. XML was originally designed for interoperability so that company A could share information with company B. When used this way the industry would decide what a "Customer" object was then so long as company A and B used this definition then they could share data. DTD, schemas and namespaces are used to enforce this. But this only really took off in the B2B world. In the B2C world where the same company is both the producer and consumer of the data (a web page posting a request to a web service and then consuming the response) JSON works fine, is much less verbose and maps to Javascript without manual parsing.
ste5anSenior Developer
You should pick your lectures more carefully..

- JSON is text. XML is text.
- JSON is an object representation of a JavaScript object. XML is language agnostic data representation.
- JSON only has string and number as data types (Boolean, NULL also). XML does not contain data types. But DTD and XML Schema can define much more data types for a XML file than JSON.
- JSON must be parsed at runtime. XML must be parsed at runtime.

what are advantages, disadvantages of each
This solely depends on the use-case.

what it mean by typed object and typeless strings and runtime parsing
Parsing, compile time, run time. Look that up.. basic concepts of how program code gets executed.

Objects are instances of classes. Or Objects are instances prototypes. The later is the case in JS. Typed objects have runtime information about their type. Thus they can be distinguished. Otherwise they needed to be compared by enumerating their interface, which allows duck typing.

David FavorFractional CTO
Distinguished Expert 2018
Reading the question my first though was, depends heavily on what you're trying to accomplish.

Describe your application in detail + likely you'll receive some great suggestions.
Theo KouwenhovenApplication Consultant
Hi gudii9,

They are all right.
To my opinion they both serve the same goal, but most of the time the XML version is the professional solution (hey..just an opinion)

You stated "All XML values are typeless strings and must be parsed at runtime"
Correct, but normally you define a XML in an XSD and that is a format that goes far beyond the Json possibilities.
Where JSON needs a document to explain the communication partner what to deliver, the XSD is importable as template, and  don't need much explanation (if right defined)

Using Webservices, the XSD is part of the WSDL and no extensive template documentation is required.
Top Expert 2014
JSON entities is lighter than XML, JSON objects are easier to use with Javascript
XML is strongest when you need to validate XML entities with XSD and/or apply transformation using XSLT (do a PDF, MS Word, a picture,...)
ste5anSenior Developer

Just again: JSON represents an object. XML is only data.

JSON objects are DTOs, so only data too. From the json.org "JSON (JavaScript Object Notation) is a lightweight data-interchange format"

So json object are no more objects than their XML counterpart. The difference between the two is simply syntax. You can even write some XSLT to transform the XML to json they are that similar.

Json is used very widely in restful services whereas XML tends to be used in traditional RPC web services.

If you are free to choose, I'd go with json as it is now more widely used and the tooling is maturing. It is more easily consumed by browsers and has a lower bandwidth requirement.

Technically, anything you can do with one can be done with the other. In some circumstances one will be easier than the other - it all depends on who your consumer is.
Theo KouwenhovenApplication Consultant

Sorry ste5an,

Json is just formatted data.
XML is a markup language.

I even use a XML script-language in our ESB to create Webservices.
Theo KouwenhovenApplication Consultant

I propose to divide the points evenly
Theo KouwenhovenApplication Consultant

There is not a right or wrong answer on a "what are differences" question