zpoley/json-command

npm install json

Closed this issue · 5 comments

This command installs another tool from https://github.com/trentm/json

Interesting, could provide any other information? I was able to install the package listed as json in npmjs.org using: npm install json

[ec2-user@ip-172-31-40-70 ~]$ npm list
/home/ec2-user
└── (empty)

[ec2-user@ip-172-31-40-70 ~]$
[ec2-user@ip-172-31-40-70 ~]$
[ec2-user@ip-172-31-40-70 ~]$ npm install json
npm http GET https://registry.npmjs.org/json
npm http 200 https://registry.npmjs.org/json
npm http GET https://registry.npmjs.org/json/-/json-0.0.14.tgz
npm http 200 https://registry.npmjs.org/json/-/json-0.0.14.tgz
json@0.0.14 node_modules/json
[ec2-user@ip-172-31-40-70 ~]$
[ec2-user@ip-172-31-40-70 ~]$
[ec2-user@ip-172-31-40-70 ~]$
[ec2-user@ip-172-31-40-70 ~]$ json --help
Usage:
| json [OPTIONS] [LOOKUPS...]
json -f FILE [OPTIONS] [LOOKUPS...]

Pipe in your JSON for pretty-printing, JSON validation, filtering,
and modification. Supply one or more LOOKUPS to extract a
subset of the JSON. HTTP header blocks are skipped by default.
Roughly in order of processing, features are:

Grouping:
Use '-g' or '--group' to group adjacent objects, separated by
by no space or a by a newline, or adjacent arrays, separate by
by a newline. This can be helpful for, e.g.:
$ cat *.json | json -g ...
and similar.

Execution:
Use the '-e CODE' option to execute JavaScript code on the input JSON.
$ echo '{"name":"trent","age":38}' | json -e 'age++'
{
"name": "trent",
"age": 39
}
If input is an array, this will automatically process each
item separately.

Conditional filtering:
Use the '-c CODE' option to filter the input JSON.
$ echo '[{"age":38},{"age":4}]' | json -c 'age>21'
[{"age":38}]
If input is an array, this will automatically process each
item separately. Note: 'CODE' is JavaScript code.

Lookups:
Use lookup arguments to extract particular values:
$ echo '{"name":"trent","age":38}' | json name
trent

Use '-a' for array processing of lookups and tabular output:
$ echo '{"name":"trent","age":38}' | json name age
trent
38
$ echo '[{"name":"trent","age":38},
{"name":"ewan","age":4}]' | json -a name age
trent 38
ewan 4

In-place editing:
Use '-I, --in-place' to edit a file in place:
$ json -I -f config.json # reformat
$ json -I -f config.json -c 'this.logLevel="debug"' # add field

Pretty-printing:
Output is 'jsony' by default: 2-space indented JSON, except a
single string value is printed without quotes.
$ echo '{"name": "trent", "age": 38}' | json
{
"name": "trent",
"age": 38
}
$ echo '{"name": "trent", "age": 38}' | json name
trent

Use '-j' or '-o json' for explicit JSON, '-o json-N' for N-space indent:
$ echo '{"name": "trent", "age": 38}' | json -o json-0
{"name":"trent","age":38}

Options:
-h, --help Print this help info and exit.
--version Print version of this command and exit.
-q, --quiet Don't warn if input isn't valid JSON.

-f FILE Path to a file to process. If not given, then
stdin is used.
-I, --in-place In-place edit of the file given with '-f'.
Lookups are not allow with in-place editing
because it makes it too easy to lose content.

-H Drop any HTTP header block (as from curl -i ...).
-g, --group Group adjacent objects or arrays into an array.
--merge Merge adjacent objects into one. Keys in last
object win.
--deep-merge Same as '--merge', but will recurse into objects
under the same key in both.
-a, --array Process input as an array of separate inputs
and output in tabular form.
-A Process input as a single object, i.e. stop
'-e' and '-c' automatically processing each
item of an input array.
-d DELIM Delimiter char for tabular output (default is ' ').
-D DELIM Delimiter char between lookups (default is '.'). E.g.:
$ echo '{"a.b": {"b": 1}}' | json -D / a.b/b

-e CODE Execute the given JavaScript code on the input. If input
is an array, then each item of the array is processed
separately (use '-A' to override).
-c CODE Filter the input with JavaScript CODE. If CODE
returns false-y, then the item is filtered out. If
input is an array, then each item of the array is
processed separately (use '-A' to override).

-k, --keys Output the input object's keys.
-n, --validate Just validate the input (no processing or output).
Use with '-q' for silent validation (exit status).

-o, --output MODE Specify an output mode. One of
jsony (default): JSON with string quotes elided
json: JSON output, 2-space indent
json-N: JSON output, N-space indent, e.g. 'json-4'
inspect: node.js util.inspect output
-i shortcut for -o inspect
-j shortcut for -o json

See http://trentm.com/json for more docs and
https://github.com/trentm/json for project details.

I am confused @lolapriego, is this still an issue, or was it just that you had the other package installed?

I am sorry, the json command of trentm was already installed on the AWS instances. But not as npm dependency, so that's the reason why after installing this one with npm, the shell first took the other command.

Cool. Thanks for closing @lolapriego.