- Notifications
You must be signed in to change notification settings - Fork121
A "json" command for massaging JSON on your Unix command line.
License
trentm/json
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
json
is a fast CLI tool for working with JSON. It is a single-file node.jsscript with no external deps (other thannode.js itself). A quick taste:
$ echo '{"foo":"bar"}' | json{ "foo": "bar"}$ echo '{"foo":"bar"}' | json foobar$ echo '{"fred":{"age":42}}' | json fred.age # '.' for property access42$ echo '{"age":10}' | json -e 'this.age++'{ "age": 11}# `json -ga` (g == group, a == array) for streaming mode$ echo '{"latency":32,"req":"POST /widgets"}{"latency":10,"req":"GET /ping"}' | json -gac 'this.latency > 10' reqPOST /widgets
Features:
- pretty-printing JSON
- natural syntax (like JS code) for extracting particular values
- get details on JSON syntax errors (handy for config files)
- filter input JSON (see
-e
and-c
options) - fast stream processing (see
-ga
) - JSON validation
- in-place file editing
Seehttps://trentm.com/json for full docs and examples as a man page.
Follow@trentmickfor updates to json.
Getnode.
npm install -g json
Note: This used to be called 'jsontool' in the npm registry, but as ofversion 8.0.0 it has taken over the 'json' name. Seenpm PackageName below.
OR manually:
Get the 'json' script and put it on your PATH somewhere (it is a single filewith no external dependencies). For example:
cd ~/bin curl -L https://github.com/trentm/json/raw/master/lib/json.js > json chmod 755 json
You should now have "json" on your PATH:
$ json --versionjson 9.0.0
WARNING for Ubuntu/Debian users: There is a current bug in Debian stablesuch that "apt-get install nodejs" installed anodejs
binary instead of anode
binary. You'll either need to create a symlink fornode
, change thejson
command's shebang line to "#!/usr/bin/env nodejs" or usechrislea's PPA asdiscussed onissue #56. You can also do "apt-get install nodejs-legacy" to install symlink fornode
with apt.
npm test # or 'make test'
This is using node-tap, so you can use allits options,for example filtering which tests to run:
npm test -- -g stream
MIT (see the fine LICENSE.txt file).
Since v1.3.1 you can use "json" as a node.js module:
var json = require('json');
However, so far the module API isn't that useful and the CLI is the primaryfocus.
Once upon a time,json
was a different thing (seezpoley's json-commandhere), and this module wascalledjsontool
in npm. As of version 8.0.0 of this module,npm install json
means this tool.
If you see documentation referring tojsontool
, it is most likelyreferring to this module.
- jq:https://stedolan.github.io/jq/
- json:select:https://jsonselect.org/
- json-command:https://github.com/zpoley/json-command
- JSONPath:https://goessner.net/articles/JsonPath/,https://code.google.com/p/jsonpath/wiki/Javascript
- jsawk:https://github.com/micha/jsawk
- jshon:https://kmkeen.com/jshon/
- json2:https://github.com/vi/json2
- fx:https://github.com/antonmedv/fx
About
A "json" command for massaging JSON on your Unix command line.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.