Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jpp which is an extended superset of the jp command #30

Closed
wants to merge 17 commits into from

Conversation

zmedico
Copy link
Contributor

@zmedico zmedico commented Jun 15, 2021

This PR contains the master branch of https://github.com/pipebus/jpp, which adds jpp, an extended superset of the jp command:

An extended superset of the jp CLI for JMESPath

Usage:
  jpp [<options>] [expression] [flags]

Flags:
  -a, --accumulate         Accumulate all output objects into a single recursively merged output object.
      --ast                Only print the AST of the parsed expression.  Do not rely on this output, only useful for debugging purposes.
  -c, --compact            Produce compact JSON output that omits nonessential whitespace.
  -e, --expr-file string   Read JMESPath expression from the specified file.
  -f, --filename string    Read input JSON from a file instead of stdin.
  -h, --help               show usage and exit
  -R, --raw-input          Read raw string input and box it as JSON strings.
  -r, --raw-output         If the final result is a string, it will be printed without quotes (an alias for --unquoted).
  -s, --slurp              Read one or more input JSON objects into an array and apply the JMESPath expression to the resulting array.
  -u, --unbox              If the final result is a list, unbox it into a stream of output objects that is suitable for consumption by --slurp mode.
      --unquoted           If the final result is a string, it will be printed without quotes.

This command has everything that I need to replace jq in my shell scripts.

I've also added a compatible python implementation of jpp to the jpipe package, so a python implementation can be installed via pip install jpipe:

pipebus/jpipe@4ca9dd3bdf36cf16b1a10a670da8f3eafd7d3388^...8acf6dc

The jpp command is now available on Gentoo Linux via either the app-misc/jp or app-misc/jpipe packages.

I've submitted the python implementation for inclusion in jmespath/jmespath.py#224.

zmedico and others added 7 commits June 14, 2021 19:19
Rename the command from jp to jpp and nothing more.
Read one or more input JSON objects into an array and apply the
JMESPath expression to the resulting array.
… into a single recursively merged object

This option will accumulate all output objects into a single
recursively merged output object. Most of this code comes from the
golang playground link posted by Roger Peppe in this
"Recursively merge JSON structures" thread:

https://groups.google.com/g/golang-nuts/c/nLCy75zMlS8/m/O9ZMubnKCQAJ
https://play.golang.org/p/8jlJUbEJKf
@zmedico zmedico changed the title Add jpp which is an is an extended superset of the jp command Add jpp which is an extended superset of the jp command Jun 15, 2021
…nt nested lists

Fixes: e7989df ("jpp: Add --accumulate, -a option which accumulates all output objects into a single recursively merged object")
zmedico added a commit to pipebus/jmespath.py that referenced this pull request Jun 15, 2021
$ jpp --help
usage: jpp [-h] [-a] [-c] [-e EXPR_FILE] [-f FILENAME] [-s] [-u] [--ast] [expression]

  jpp is an extended superset of the jp CLI for JMESPath

positional arguments:
  expression

optional arguments:
  -h, --help            show this help message and exit
  -a, --accumulate      Accumulate all output objects into a single recursively merged output object.
  -c, --compact         Produce compact JSON output that omits nonessential whitespace.
  -e EXPR_FILE, --expr-file EXPR_FILE
                        Read JMESPath expression from the specified file.
  -f FILENAME, --filename FILENAME
                        The filename containing the input data. If a filename is not given then data is read from stdin.
  -s, --slurp           Read one or more input JSON objects into an array and apply the JMESPath expression to the resulting array.
  -u, --unquoted        If the final result is a string, it will be printed without quotes.
  --ast                 Only print the AST of the parsed expression. Do not rely on this output, only useful for debugging purposes.

There's also a golang implementation in jmespath/jp#30.
zmedico added 9 commits June 16, 2021 09:22
If the final result is a list, unbox it into a stream of output
objects that is suitable for consumption by --slurp mode.

See: jqlang/jq#878
…ns --unbox now)

$ ./jpp --help
An extended superset of the jp CLI for JMESPath

Usage:
  jpp [<options>] [expression] [flags]

Flags:
  -a, --accumulate         Accumulate all output objects into a single recursively merged output object.
      --ast                Only print the AST of the parsed expression.  Do not rely on this output, only useful for debugging purposes.
  -c, --compact            Produce compact JSON output that omits nonessential whitespace.
  -e, --expr-file string   Read JMESPath expression from the specified file.
  -f, --filename string    Read input JSON from a file instead of stdin.
  -h, --help               show usage and exit
  -R, --raw-input          Read raw string input and box it as JSON strings.
  -r, --raw-output         If the final result is a string, it will be printed without quotes (an alias for --unquoted).
  -s, --slurp              Read one or more input JSON objects into an array and apply the JMESPath expression to the resulting array.
  -u, --unbox              If the final result is a list, unbox it into a stream of output objects that is suitable for consumption by --slurp mode.
      --unquoted           If the final result is a string, it will be printed without quotes.
@jamesls
Copy link
Member

jamesls commented Sep 29, 2021

Thanks! This is awesome. I'd like to take some time to go through this in more detail, but looking over most of these arguments, they seem like they'd be great additions to jp.

@jamesls
Copy link
Member

jamesls commented Mar 31, 2023

Closing out old PR. Happy to discuss features to merge back into the jp executable.

@jamesls jamesls closed this Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants