json-machine icon indicating copy to clipboard operation
json-machine copied to clipboard

CLI script for streaming

Open pkoppstein opened this issue 3 years ago • 8 comments

@halaxa asked me to start a new thread stemming from the discussion at https://github.com/halaxa/json-machine/issues/73

Hopefully the script described below, which I'll call jm, will provide a basis for discussion or perhaps even the foundation of a script worthy of inclusion in the JSON Machine repository.

The --help option produces quite extensive documentation, so for now I'll just add two points:

  1. The script attempts to make installation as painless as possible for the uninitiated, and I hope that further enhancements in that regard will be added;
  2. Ideally, the script would preserve the precision of all JSON numbers (at least as the default) -- see https://github.com/halaxa/json-machine/issues/87

[ EDIT: The jm script is now in the "jm" repository. ]

pkoppstein avatar Oct 12 '22 17:10 pkoppstein

Thank you. I'm already prototyping the CLI. You really put an effort into the help. May I alternatively use some parts of it?

halaxa avatar Oct 12 '22 20:10 halaxa

Of course, that's why I've posted here!

pkoppstein avatar Oct 12 '22 20:10 pkoppstein

;)

halaxa avatar Oct 12 '22 20:10 halaxa

@halaxa -- Assuming (as I do) that the default encoder should be the PassThruDecoder, should there be an option to use the standard one? If so, what should it be called? Since the main point would be to convert JSON numbers to their PHP equivalent, I'm thinking of "--recode" or perhaps "--php". I think any any variation of encode or decode would be too confusing. Your thoughts?

pkoppstein avatar Oct 13 '22 02:10 pkoppstein

Here's jm Version 0.0.5, which uses the PassThruDecoder to preserve numeric literals. It also has the side-effect of allowing mal-formed JSON, but maybe that's not such a bad thing?

[ EDIT: The version originally referenced (i.e., using the PassThruDecoder) can be viewed here at the jm repository ]

pkoppstein avatar Oct 13 '22 02:10 pkoppstein

The jm script now has a bunch of options making it quite a handy tool for a variety of tasks. jm --help gives detailed help. Here's the output of jm -h:

Usage: jm [ OPTIONS ]  [ FILEPATH ... ]
or:    jm [-h | --help]
where JSONPOINTER defaults to '' and FILEPATH defaults to stdin, and the other options are:
     -s
     --array
     --bigint_as_string | --recode
     --count | --limit=LIMIT
     --pointer=JSONPOINTER

pkoppstein avatar Oct 15 '22 05:10 pkoppstein

Thanks for the hints. The count option is a good idea. The version I'm currently working on will also include tests and offer extensibility to some degree. I hope the PR will land soon. I'll appreciate your feedback then.

halaxa avatar Oct 15 '22 11:10 halaxa

I'm adding a --version option to jm and would like to include the JSON Machine version number, but I don't see an easy way to report it reliably. Searching for the version string in CHANGELOG.md doesn't seem either efficient or reliable.

Could perhaps JSON Machine provide a function to report its version number?

pkoppstein avatar Oct 16 '22 03:10 pkoppstein