# json

> a 'json' command for massaging and processing JSON on the command line

Latest version **11.0.0** (published 2021-04-27) · 0 weekly downloads

## Install

```sh
npm install json
pnpm add json
yarn add json
bun add json
```

Provides the command `json`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 11.0.0 |
| Published | 2021-04-27 |
| First published | 2011-02-26 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 0 |
| Unpacked size | 122.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1561 |
| Author | Trent Mick |
| Maintainers | trentm |
| Keywords | json, jsontool, filter, command, shell |

## Links

- npm: https://www.npmjs.com/package/json
- Repository: https://github.com/trentm/json
- Homepage: https://github.com/trentm/json#readme
- Issues: https://github.com/trentm/json/issues
- npm.io page: https://npm.io/package/json

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 11.0.0 (latest) — 2021-04-27
- 10.0.0 — 2020-08-28
- 9.0.6 — 2017-03-03
- 9.0.5 — 2017-03-03
- 9.0.4 — 2016-06-03
- 9.0.3 — 2015-01-17
- 9.0.2 — 2014-10-28
- 9.0.1 — 2014-05-30
- 9.0.0 — 2014-05-26
- 8.0.0 — 2014-05-12
- 0.0.14 — 2013-08-12
- 0.0.13 — 2013-04-05
- 0.0.12 — 2012-06-24
- 0.0.11 — 2012-05-29
- 0.0.10 — 2012-02-29
- … 2 more at https://npm.io/package/json/versions

## README

`json` is a fast CLI tool for working with JSON. It is a single-file node.js
script with no external deps (other than
[node.js](https://github.com/joyent/node) itself). A quick taste:

    $ echo '{"foo":"bar"}' | json
    {
      "foo": "bar"
    }

    $ echo '{"foo":"bar"}' | json foo
    bar

    $ echo '{"fred":{"age":42}}' | json fred.age    # '.' for property access
    42

    $ 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' req
    POST /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

See <https://trentm.com/json> for full docs and examples as a man page.

Follow <a href="https://twitter.com/intent/user?screen_name=trentmick" target="_blank">@trentmick</a>
for updates to json.


# Installation

1. Get [node](http://nodejs.org).

2. `npm install -g json`

   *Note: This used to be called 'jsontool' in the npm registry, but as of
   version 8.0.0 it has taken over the 'json' name. See [npm Package
   Name](#npm-package-name) below.*

**OR manually**:

2. Get the 'json' script and put it on your PATH somewhere (it is a single file
   with 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 --version
    json 9.0.0


**WARNING for Ubuntu/Debian users:** There is a current bug in Debian stable
such that "apt-get install nodejs" installed a `nodejs` binary instead of a
`node` binary. You'll either need to create a symlink for `node`, change the
`json` command's shebang line to "#!/usr/bin/env nodejs" or use
[chrislea's PPA](https://launchpad.net/~chris-lea/+archive/node.js/) as
discussed on [issue #56](https://github.com/trentm/json/issues/56). You can also do "apt-get install nodejs-legacy" to install symlink for `node` with apt.

# Test suite

    make test

You can also limit (somewhat) which tests are run with the `TEST_ONLY` envvar,
e.g.:

    cd test && TEST_ONLY=executable nodeunit test.js

I test against node 0.4 (less so now), 0.6, 0.8, and 0.10.


# License

MIT (see the fine LICENSE.txt file).


# Module Usage

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 primary
focus.


# npm Package Name

Once upon a time, `json` was a different thing (see [zpoley's json-command
here](https://github.com/zpoley/json-command)), and this module was
called `jsontool` in npm. As of version 8.0.0 of this module, `npm install json`
means this tool.

If you see documentation referring to `jsontool`, it is most likely
referring to this module.


# Alternatives you might prefer

- jq: <http://stedolan.github.io/jq/>
- json:select: <http://jsonselect.org/>
- json-command: <https://github.com/zpoley/json-command>
- JSONPath: <http://goessner.net/articles/JsonPath/>, <http://code.google.com/p/jsonpath/wiki/Javascript>
- jsawk: <https://github.com/micha/jsawk>
- jshon: <http://kmkeen.com/jshon/>
- json2: <https://github.com/vi/json2>
- fx: <https://github.com/antonmedv/fx>

---
_Source: https://npm.io/package/json · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
