Simple question, for which so far I haven't easily found an answer. (Similar Questions suggested as I type this point to nothing relevant - but I can't believe I'm the only person facing this challenge.)
Say I have an object in memory which contains
- simple types (e.g. name, computer name, creation date, configuration, etc.); and
- a collection of some kind (e.g. time series of statistical measures, e.g. moving average)
To serialize these it makes sense
- to store the simple types in a fully-featured serialization format e.g. JSON, XML, YAML
- to store the collection values in CSV file (to save needless repetition of the tags for each entry)
But this means I end up with two files. It is better if all the info is in one file, so that unambiguously the reader can understand that (2) results from (1). Also easier to maintain in the file system.
I don't want to combine into a BLOB as this would lose human readability.
Is there a simple technique for combining the JSON in (1) and CSV for (2) into one file?
My first guess would be to have (say) XML tags to separate the different types. e.g.
<SimpleTypes format="JSON">
[JSON for simple types]
</SimpleTypes>
<Collection format="CSV" type="Dictionary" name="DailySalesTotal">
[CSV for collection]
</Collection>
<Collection format="CSV" type="Dictionary" name="DailyFootfallInStore">
[CSV for collection]
</Collection>
Then just open up the file, parse the XML into separate JSON and CSV sections and handle as normal.
Is this a sensible approach? Any risks?
Or is there a library anywhere for this? I'm using C# so would need a .NET library.