3 ms·
Why not use a “stream” of objects? {"cmd": "git checkout", "when": 1234} {"cmd": "vagrant up", "when": 4567} Not sure about other languages and libraries,
by ainar-g 7y ago
Why not use a “stream” of objects?
{"cmd": "git checkout", "when": 1234}
{"cmd": "vagrant up", "when": 4567}
Not sure about other languages and libraries, but Go supports this out of the box[1]. And while we're at it, why not CSV? That can be processed with awk.
#cmd,when
"git checkout","1234"
"vagrant up","4567"
[1]: https://play.golang.org/p/sTN9z4Kv3DB https://play.golang.org/p/sTN9z4Kv3DB
- ridiculous_fish 7y agoCSV is fine for simple cases but has issues with versioning (adding new/optional fields) and nested data like arrays. The object stream idea is apparently supported widely and seems pretty strong. Thanks for the suggestion!
- zenexer 7y agoI use JSON streams a lot with command line tools. Keep in mind that it’s limited in that each object must consume a single line. This allows you to recover from syntax errors in a single entry; each line is a fresh start. Have you considered SQLite? I know it’s not a friendly text format, but it alleviates a lot of the issues with the “append to a text file” approach, such as concurrency. It’s great for this sort of thing.