jprichardson / node-jsonfile

Easily read/write JSON files.
MIT License
1.2k stars 321 forks source link

Add support for JSONL format #121

Closed marycourtland closed 4 years ago

marycourtland commented 5 years ago

Since the append option (i.e. flag: "a") in jsonfile.writeFile simply appends the new JSON object to the end of the file, it produces a file which is compatible with the JSONL format. It would be convenient if this file was readable with jsonfile.readFile, which would return an array of the objects in the file.

The only catch is that JSONL requires each line to be valid JSON. This means that it's incompatible with the spaces formatting option.

I think it would be best to require an explicit option to be passed to readFile, rather than implicitly detecting the format. (E.g. format: "jsonl")

Related issue: https://github.com/jprichardson/node-jsonfile/issues/52 (and many other closed issues). This is not suggesting the same functionality, but it solves the same problem.

RyanZim commented 5 years ago

We'd have to have a jsonl option for writeFile for writing out an array in jsonl format for creating new jsonl files.

RyanZim commented 4 years ago

@jprichardson what are your thoughts here? Is this out of scope?

jprichardson commented 4 years ago

what are your thoughts here? Is this out of scope?

yes