Field notes
CSV, JSON or XML: Choosing a Format for Your Log Archive
Which file format should a long-term log archive use? A plain comparison of CSV, JSON and XML, what archivists recommend, and what to store beside the file.
For a log you want to read in five years, use CSV when your entries are flat rows, use XML or JSON when the data is nested and comes with a schema, and keep the original export whichever you choose. The format matters less than two habits: documenting what each column means, and never deleting the file the export tool first gave you.
This piece compares the three as archive formats, not as ways to move data between programs. It leans on two archival guides and on what common export tools list. It doesn't tell you what to log.
Where your export comes from#
You rarely pick a format from scratch. The tool picks one for you, so find out which before you plan an archive.
Apple Health's built-in export has produced XML. A 2019 walkthrough from AppleToolBox says the Health app "exports your data as an XML file," that the exported data is unencrypted, and that parsing it by eye is "not very easy." That article is old, so check what your current Health app produces before you rely on it.
Third-party export apps usually add the formats people open in spreadsheets. The Health Auto Export listing says it exports health and fitness metrics in CSV, JSON, Markdown or GPX. A reviewer on that listing reported some metrics missing, so an export is only as complete as the app that made it. Compare a sample against the source before you trust it.
What each format does well#
The three formats store the same facts in different shapes.
| Format | Shape | Strength | Weakness | |---|---|---|---| | CSV | Flat rows and columns | Opens in any spreadsheet, tiny, easy to read | No nesting, no built-in types or units | | JSON | Nested key and value pairs | Holds records inside records, readable text | No built-in schema, meaning depends on you | | XML | Nested tags | Can be paired with a published schema | Verbose, awkward to read by eye |
CSV#
A CSV file is one header row and many data rows. Anything with one value per column fits well: a date, a value, a unit, a note. The usual trouble is that CSV can't say which column is a number and which is text. Dates and decimal separators are the classic traps. Write down the convention you used.
JSON#
JSON handles entries that carry a variable amount of detail, such as a workout with a list of samples inside it. The cost: a flat spreadsheet can't open it directly. You end up flattening it, and every flattening is a decision about which detail to drop.
XML#
XML does the same nesting with tags. Its one real advantage for an archive is that it can travel with a schema stating what each element may contain. Without that schema, it's just a wordier JSON.
What archives recommend#
Archival guidance is the best neutral source here. Archivists plan for decades, not for next month's app update.
The Library of Congress Recommended Formats Statement for datasets says platform-independent, character-based formats are preferred over native or binary formats "as long as data is complete, and retains full detail and precision." It names CSV among its preferred line-oriented formats. It does not name JSON or XML as preferred dataset formats; its list of text-based options asks for an available schema. For character encoding it ranks UTF-8 first.
King's College London's guide to choosing file formats lists CSV and XML among its examples of open formats, and explains why openness helps: when the code behind a format is public, it "reduces the risk of software or hardware obsolescence." JSON does not appear on that page, which says something about how old the guidance is, not about JSON's quality.
The practical reading is modest. CSV is the safest bet for flat data, a text format with a schema is a reasonable choice for nested data, and a closed or app-specific file is the risky one.
Keep the original export#
Converting between formats can lose detail. King's College London advises checking a converted file for errors or loss, and keeping a copy of important data in the original format too, because some open formats lack features of the source.
So make the first export your master. Make a working copy in the format you will actually open, check a handful of rows against the master, and store both. If you rely on an encrypted backup, remember that the password decides whether the file can be read at all, so record where that password is kept.
What to store next to the file#
A file without context is hard to trust later. The Library of Congress guidance asks that deposits carry a data dictionary, a key to each field, the character encoding, checksums and version information. A short text file beside your archive can cover all of that:
- The export date and the app or tool that produced it, with its version.
- A line for each column: its name, its unit and what a blank means.
- The character encoding, ideally UTF-8.
- A checksum of the original file, so you can tell later whether it changed.
- The time zone convention, since the offset belongs to the export, not the entry.
- Whether values are in display units or stored units.
OptimizedTracker keeps entries as dated rows for the same reason: a row with a date, a value and a unit survives a change of tools better than one that depends on the app that wrote it. You can see how it is set up on the homepage.
When CSV is the right choice#
Choose CSV when each entry is one flat row, when you will open the file in a spreadsheet, and when you can write the column notes yourself. A blood work spreadsheet laid out by panel is a good example of data that fits that shape.
Choose JSON or XML when entries carry nested detail you do not want to flatten, and keep the schema or a written description with them. If the data came out of a tool as XML, keep that XML as the master and make CSV copies from it for reading.
Conclusion#
No format keeps a log readable by itself. A flat CSV with a data dictionary, a UTF-8 encoding note and a checksum will outlast a nested file nobody described. Pick the format you can open without special software, document every column, and keep the original export beside your working copy.
Share
Related
01
