What is the best file format for parsing?

Scenario: I am working on a rails application that will accept data as downloaded text files. I need to parse these files before importing data. I can choose the type of file loaded into the application; the software (Microsoft Access) used by these downloads has several export options regarding the file type.

While this may be minor, I was curious to see if there is a particular file type that is most efficiently parsed. I think this question can be viewed as language independent.

(Although XML is usually parsed, it is not a valid file type for this project.)

+2


a source to share


4 answers


If it's something Access exported, CSV is the simplest; in particular since Ruby contains a CSV parser in the standard library . You will need to do some work defining the CSV dialect (what it uses for the delimiter, how does it handle quotes); I don't know how reliable the ruby ​​parser was with these problems, but you should also have some control over Microsoft Access.



+2


a source


You might want to take a look at JSON . It is a lightweight format, and unlike XML it is very simple and clean to parse without requiring a huge library on the backend.



It can represent types such as strings, numbers, associative arrays (objects) and lists of such

+2


a source


I would suggest n-SV (where n is some character) for data that does not contain n. This will make lexing files a question split

.

If you have more flexible data I would suggest JSON.

0


a source


If you need to roll up your own parser, I would suggest CSV or some kind of delimiter delimited format.

If you can use other libraries, there are many options. JSON looks pretty cool.

0


a source







All Articles