json vs xml

gudii9
gudii9 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
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
Commented:
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.

Commented:
Ditto
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

David FavorLinux/LXD/WordPress/Hosting Savant
Distinguished Expert 2018
Commented:
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
Commented:
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.
Multitechnician
Top Expert 2014
Commented:
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

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

Commented:
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

Commented:
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

Commented:
I propose to divide the points evenly
Theo KouwenhovenApplication Consultant

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial