Skip to content

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

Closed
zmedico wants to merge 17 commits into
jmespath:masterfrom
pipebus:add-jpp-command
Closed

Add jpp which is an extended superset of the jp command#30
zmedico wants to merge 17 commits into
jmespath:masterfrom
pipebus:add-jpp-command

Conversation

@zmedico

@zmedicozmedico commented Jun 15, 2021

Copy link
Copy Markdown
Contributor

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.

zmedicoand 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/O9ZMubnKCQAJhttps://play.golang.org/p/8jlJUbEJKf
@zmedicozmedico changed the title Add jpp which is an is an extended superset of the jp commandAdd jpp which is an extended superset of the jp commandJun 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.
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
Copy Markdown
Member

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
Copy Markdown
Member

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

@jameslsjamesls closed this Mar 31, 2023
Sign up for freeto 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

@zmedico@jamesls