ion-cli icon indicating copy to clipboard operation
ion-cli copied to clipboard

Add a `jq`-like subcommand

Open popematt opened this issue 2 years ago • 2 comments

The jq tool is cited as one of the reasons for wanting to downconvert to JSON in #40. If ion-cli had a subcommand with similar functionality, it would be one less reason not to use Ion, and it would make it easier to manipulate Ion data in shell scripts.

popematt avatar Jan 18 '23 18:01 popematt

Well this would be great, I do want to point out that it may be a lot of effort, as jq has its own language and everything. The feature is also against the Unix philosophy of doing one thing well.

That being said down-casting to JSON, using jq, and re-casting to ion could be a common practice. Is there something that could make the pipeline less lossy?

SimplyKnownAsG avatar Jan 18 '23 21:01 SimplyKnownAsG

You're right— it is a lot of effort (which is why we don't have one yet).

With the Ion CLI, we're taking a similar approach to git and cargo where the top-level command is really just an entry point to other commands. We would like each of the subcommands to do one thing well.

Is there something that could make the pipeline less lossy?

Anything that would make the pipeline less lossy would result in changing the structure of the data in order to capture the Ion types and annotations in the JSON output. For example, we could convert Ion foo::1.0 to { ion_type: "decimal", ion_annotations: ["foo"], ion_value: "1.0" }. This would preserve all of the information in foo::1.0, but it's a completely different shape compared to the original data (that would probably be unintuitive to work with in jq), and we are hesitant to define any sort of Ion-over-Json specification that would be required to transform to json and then back to Ion with full fidelity.

If it helps with your use case, you could convert Ion to a form like the one I've illustrated above... but you'd be writing some bespoke code to make it happen.

popematt avatar Jan 18 '23 22:01 popematt