Namby Pamby Magicians

    jspath-cli

    0.1.6 • Public • Published

    jspath-cli

    js-standard-style Build Status Coverage Status

    Dependency Status devDependency 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 type output of single output of multiple
    Array Array Array of arrays' values
    Object Object Array of objects
    Boolean Boolean Array of booleans
    Number Number Array of numbers
    String String unquoted Array of strings
    Mixed N/A Array of mixed

    Strict mode

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

    matched type output of single output of multiple
    Array Array Array of arrays' values
    Object Array of one object Array of objects
    Boolean Array of one boolean Array of booleans
    Number Array of one number Array of numbers
    String Array of one string unquoted Array of strings
    Mixed N/A Array 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.

    Keywords

    Install

    npm i jspath-cli

    DownloadsWeekly Downloads

    150

    Version

    0.1.6

    License

    MIT

    Last publish

    Collaborators

    • cstruct