Skip to content
This repository was archived by the owner on Oct 27, 2023. It is now read-only.

Latest commit

History

43 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

jspath-cli

js-standard-styleBuild StatusCoverage Status

Dependency StatusdevDependency Status

Commitizen friendly

NPM

A small CLI wrapper around JSPath. Support for working with stdin and file paths

Installation

npm install -g jspath-cli

Usage

With a file path:

jspath '.some.path' some-file.json

With stdin:

cat some-file.json | jspath '.some.path'

Options

  • Use -h or --help to show help output.
  • Use --version to display program version.
  • Use -p or --pretty to enable pretty printing of output.
  • Use -s or --strict to enable strict mode

Normal mode

To simplify usage in pipes results always try to be returned in it's most simplified form. This is done by not wrapping in unnecessary data structures and having singely matched strings printed unquoted.

matched typeoutput of singleoutput of multiple
ArrayArrayArray of arrays' values
ObjectObjectArray of objects
BooleanBooleanArray of booleans
NumberNumberArray of numbers
StringString unquotedArray of strings
MixedN/AArray of mixed

Strict mode

By enabling strict mode all results are returned as a valid JSON array of matches.

matched typeoutput of singleoutput of multiple
ArrayArrayArray of arrays' values
ObjectArray of one objectArray of objects
BooleanArray of one booleanArray of booleans
NumberArray of one numberArray of numbers
StringArray of one string unquotedArray of strings
MixedN/AArray of mixed

Examples

Simple

The example from JSPath:

$ echo' { "automobiles" : [ { "maker" : "Nissan", "model" : "Teana", "year" : 2011 }, { "maker" : "Honda", "model" : "Jazz", "year" : 2010 }, { "maker" : "Honda", "model" : "Civic", "year" : 2007 }, { "maker" : "Toyota", "model" : "Yaris", "year" : 2008 }, { "maker" : "Honda", "model" : "Accord", "year" : 2011 } ], "motorcycles" : [{ "maker" : "Honda", "model" : "ST1300", "year" : 2012 }] }'| jspath '.automobiles{.maker === "Honda" && .year > 2009}.model'
['Jazz', 'Accord']

Realworld

JSPath can be used to quickly work with the AWS CLI:

aws ec2 describe-instances | jspath ' .Reservations.Instances{ .Tags.Key === "service" && .Tags.Value === "someservice" }.PublicIpAddress{ . !== "1.2.3.4" }'

Support

Please open an issue for support.

Contributing

Please contribute by opening a pull request.

About

CLI wrapper for JSPath

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages