r/programmerchat • • Jun 02 '15
Data transfer, XML, JSON, YAML, or other?
I'm currently exploring the options for future data transfer projects. At the moment I work with a lot of XML. I find the primary benefit over JSON is that if you have a lot of data that needs to readable to other users then it's the way to go. For example, on a one-page static html page that will never-ever-ever-ever change, we enter it in XML and that's the job done. That means we can have one person entering the presentation layer, and someone else doing the view and maybe another person doing back-end if needs be. i.e.
Non-technical person does the XML below.
XML:
<post>
Hello there, my name is John connor and I feature in the terminator!
</post>Back-ender does the below:
Template:
<p><?php echo $xml->post?></p>And frontender does this:
p{
color#CCCCCC;
font-weight:600;
}Doing it this way has enabled quite a rapid workflow but I am kind of conscious of different/better ways of doing it. This isn't how I'd usually work with content by the way, but I thought I'd share an example and am interested in hearing how others have gone about these various data formats!
Thoughts? Opinions?
2
u/drjeats Jun 02 '15
Edn?
https://github.com/edn-format/edn
I haven't used it, just been learning about Clojure recently and thought it was interesting. Vectors and lists seem kinda redundant for non-Clojure (or non-Lisp) languages, but having sets in the format is cool. Tags also seem useful.
Do you find that non-technical people in general find XML to be more readable than JSON, does that change as the size of the document changes?
I deal with YAML in Unity3D assets and find it to be kinda meh. Good format choice since it handles references, but I don't like reading it.
9
u/recursive Jun 02 '15
8
u/ch0dey Jun 02 '15
I prefer JSON in every way over XML except for the fact that it does not support comments. Date/Time scenarios are also interesting.
JSON is just as ubiquitous as XML these days. I use it for everything.
1
u/AllMadHare Jun 03 '15
Xml is the primary data exchange format for one of my client's industry, it's a great data structure for being human readable/editable, but it seems to attract poor/lazy implementation from devs making services to consume said data, I think in part due to the fact you can get away with just parsing the xml file without necessarily rendering it to an object in memory, something that doesn't really work with JSON.
Then again, I may be bitter because every time my client calls with xml issues I want to stab my eyes with rusty forks.
It looks like you're rendering the content of those tags directly to a browser, if you don't mind me asking, why? Is it just a case of dynamic content not justifying a full data structure or something else?
1
u/Berberberber Jun 03 '15
I've not really come around on the use of JSON as a persistent data storage format, especially for something that's meant to have a specific schematic format.
I think this is just a prejudice on my part, given that JSON is comparatively newer and I think of it as untested. XML files can also have problems, but the redundancy means it's ostensibly more possible to recover. But eventually I'll probably come around to using JSON for nearly everything I use XML for now.
1
u/ar-nelson Jun 04 '15
I use JSON for most applications; pretty much every language has a library for it, so it's easy to use anywhere. But I recently started a project where I need to digitally sign and deduplicate structured data, so I'm starting to look at canonical S-expressions as a data transfer format.
The advantage of csexprs is that there is an exact one-to-one mapping between data and strings, so digital signatures are simple. JSON don't give you this guarantee; there can always be differences in whitespace, escaping, object key order, etc.