LibreCat / Catmandu

Catmandu - a data processing toolkit
https://librecat.org
176 stars 31 forks source link

Catmandu::Importer::JSON , Catmandu::Exporter::JSON naming conventions #106

Closed phochste closed 9 years ago

phochste commented 10 years ago

For the importer we have an option:

multiline => 0|1

to export into JSON arrays or JSON-per-line.

For the exporter we have the option:

array => 0|1

to export into JSON-per-line or JSON arrays.

Can these options get the same name (choose a pereference) and use the other as deprecated?

vpeil commented 9 years ago

+1,

vpeil commented 9 years ago

oh wait (I responded to quickly), these are different things:

multiline in the importer corresponds to pretty in the exporter. Basically, it's not about arrays but nice line breaks and indentation.

nichtich commented 9 years ago

This could alsr be solved by distinguish "real" JSON and jsonlines (JSONL): http://jsonlines.org

Catmandu::Exporter::JSONL : current default Catmandu::Exporter:JSON : pretty Catmandu::Importer::JSONL : current default Catmandu::Importer::JSON : multiline

This would may some backwards compatibility but its a cleaner solution

vpeil commented 9 years ago

What about @nichtich's idea? Should we implement this? Any votes?

phochste commented 9 years ago

Backwards compatibility is important for me. I've zillions of scripts around that expect JSON to be able to support both options

nics commented 9 years ago

I added some simple aliases to make the options more consistent in dcaa312cac3b98aa59987f9502cf8cb0247fa237.

importing and exporting without options defaults to jsonlines. i added multiline as an alias to pretty in the exporter. i added an array option to the importer.

this enables roundtripping from the exporter to the importer with the same options: exporter JSON | importer JSON exporter JSON --array 1 | importer JSON --array 1 exporter JSON --array 1 --multiline 1 | importer JSON --array 1--multiline 1

(array and multiline switch the importer to an incremental parser that reads all these forms: [{}, {}] [{} {}] {}, {} {} {} and their pretty printed variants)