Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML vs YAML vs JSON [closed]

Tags:

json

xml

yaml

perl

Assuming I'm starting a project from scratch, which is not dependent on any other project. I would like to use a format to store feeds, something like XML, since XML is not the only available format of its kind, I would like to know: why should I choose one over the rest?

I will be using perl.

'Feed' is a description of a product (name, price, type, short description, up to 120 words).

like image 866
snoofkin Avatar asked Oct 16 '10 22:10

snoofkin


People also ask

Is YAML more readable than JSON and XML?

YAML, depending on how you use it, can be more readable than JSON. JSON is often faster and is probably still interoperable with more systems. It's possible to write a "good enough" JSON parser very quickly.

What is the difference between XML and JSON and YAML?

YAML stands for “YAML Aint Markup Language“. JSON stands for “JavaScript Object Notation“. XML is “eXtensible Markup Language” whereas YML is not a markup language. XML uses a tag to define the structure just like HTML.

Is YAML better than XML?

The biggest difference, though, is that XML is meant to be a markup language and YAML is really more of a data format. Representing simple, hierarchical data tends to be more gracefully done in YAML, but actual marked-up text is awkward to represent.

Is XML being replaced by JSON?

Yes, JSON is rapidly replacing XML for RPC-style communication: not just AJAX from browser, but server to server.


2 Answers

We can't really answer that without knowing a lot more. Just because you're not currently dependent on any other projects, are you likely to interact with them at some point in the future? If so, what technologies do they prefer? At the BBC, we've had some projects "JSON-only", only to find out that Java developers who wanted to access our API were begging us to provide a simple XML API simply because they have so many tool built around XML. They didn't even care about namespaces, attributes, or anything else; they just wanted those angle-brackets.

As for "storing feeds", I also not sure what you mean there. You explain the data in the feed, but what are you then going to do with those feeds? Parse them? Cache and reserve them? Write them out to cuneiform tablets? :)

I sounds like what you actually want is a database and you want to persist the data there and later make it serialisable as JSON/YAML/XML or whatever your desired format is. What I'd recommend is to be able to pull the data out into a Perl data structure and then have "formatters" which know how to serialise that data structure to the desired output. That way you can serialise to, say, JSON, and later if that's not good enough, easily switch to YAML or something else. In fact, if others need your data (one-way data tends not to be useful), they can ask for JSON, YAML, XML or whatever. You have more flexibility and aren't tied into a decision that you made up front.

That being said, I don't know your system, so it's tough to say what the right thing to do is. Also, not that JSON and YAML aren't exactly interchangeable with XML. Subtle differences can and will trip you up.

like image 50
Ovid Avatar answered Oct 02 '22 12:10

Ovid


Each will do the job.

JSON has the advantage of super-easy parsing in JavaScript, though you'll probably have to find and introduce a library in other languages.

XML has the advantage that more languages bundle the relevant libraries, and is useful for the storage you mention. So, it is valuable for passing around through different systems, both "in-motion" and "at-rest".

YAML has libraries for all languages, but is somewhat less commonly used, so you are more likely to have to find and introduce a library.

like image 23
Joshua Fox Avatar answered Oct 02 '22 13:10

Joshua Fox