views:

160

answers:

4

I have written a console application in Delphi that queries information from several locations. This application will be launched by another process, and the output to STDOUT will be captured by the launching process.

The information I am retrieving is to be interpreted by the calling application for reporting purposes. What is the best way to output this data to STDOUT so that it can be easily parsed? JSON? XML? CSV? The data, specifically, is remote workstation information, so it will pull things back like running processes, and details about each process.

Does anyone have any experience with this or suggestions?

+6  A: 

If you want something that can be easily parsed, especially if it has to be done quickly, go with the simplest format that can effectively communicate the information you need. CSV if you can, otherwise try JSON. Definitely not XML unless you really, really need all the extra complexity for some reason.

Mason Wheeler
The point of XML is that standard XML libraries handle the complexity for you. So use XML only if it fits our needs *and* you use such libraries to read it, write it, validate it, etc.
reinierpost
@reubueroist as CSV and JSON... Just XML creates your files bigger and parsing much slower...
Artyom
+1 - Principles of KISS = always use the lowest common format you can get away with, XML sounds nice and JSON is very transportable - but if a tab or comma separated list will do, it will do :D
MarkRobinson
@reinierpost: Yes, standard XML libraries can handle the complexity for you, but just because some library does it under the hood instead of you doing it in your own code doesn't mean that that complexity isn't still there, or that it doesn't take a lot of system resources to parse.
Mason Wheeler
A: 

It would depend entirely on what the launching process has available. If it's a small Delphi app, CSV is easy to parse with just TStringList. XML may be more heavy weight than JSON, but Delphi ships with an XML parser, and AFAIK, not a JSON parser.

Craig Peterson
Delphi 2010 has a pretty good (thus lightweight) JSON engine.
+5  A: 

I'd go for a Tab-delimited file, if your data (as it seems) doesn't contain that character because it allows the fastest and simplest processing. All the other formats are slower and more complicated (even if they give you more power).

The closest match is CSV but CSV needs to quote the item if the item contains some special characters defined by the CSV (space, comma, quotes etc.).

Because of the above thing, the Tab delimited format is the most compact one, hence it has the greatest speed over-the-wire. (Since you're talking about remote workstations I assume that you're on some kind of network).

Also, another thing worth mentioning is that the Tab delimited format is very readable thus making the debugging much easier, if needed.

As an aside, if the Tab character is present in your data stream you can choose another character which you are sure that cannot be. (For example #1 etc.). Of course, this if your usage scenario permits it.

HTH

I use Tab-delimited URL-encoded to avoid problems in case tab characters and binary data present.
PA
A: 

The XML output format has the advantage that you can pipe it to a XSL formatter, so that the XML data can be converted to a user friendly HTML document. (You can almost have the cake and eat it too) ...

mjustin