# json-format-cli

> Command line tool for formatting json.

Latest version **1.1.1** (published 2019-05-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install json-format-cli
pnpm add json-format-cli
yarn add json-format-cli
bun add json-format-cli
```

Provides the command `json-format`.

## 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 | 1.1.1 |
| Published | 2019-05-01 |
| First published | 2018-09-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Andrew Kobylin |
| Maintainers | kobylin |
| Keywords | json, stringify, deterministic, sort, stable, cli |

## Links

- npm: https://www.npmjs.com/package/json-format-cli
- Repository: https://github.com/kobylin/format-json
- Issues: https://github.com/kobylin/format-json/issues
- npm.io page: https://npm.io/package/json-format-cli

## Dependencies (2)

- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [json-stable-stringify](https://npm.io/package/json-stable-stringify.md) ^1.0.1

## 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

- 1.1.1 (latest) — 2019-05-01
- 1.1.0 — 2018-09-19
- 1.0.2 — 2018-09-07
- 1.0.1 — 2018-09-07
- 1.0.0 — 2018-09-07

## README

# Format JSON

Command line tool for formatting json.

Based on library [json-stable-stringify](https://github.com/substack/json-stable-stringify)

### Installation

`sudo npm install json-format-cli -g`

Then use it as command line tool:
```
$ json-format foo.json
```

### What it can?

- Sorting properties alphabetically
- Formatting json with specified indentation

Can be useful when response from server is not formatted or properties come in different order every time.

### Options

```
--indent - number of chars used for indentation. 4 spaces by default
--indent-char - char used for indentation 'space' or 'tab'. space by default
```

### You can pass any numbers of files to it

`json-format foo.json bar.json`

In this case every file will be overwritten by formatted file.


### Using pipes

`cat foo.json | json-format > result.json`


`curl https://api.chucknorris.io/jokes/random | json-format`


### Formatting example

```
//input
{"category":null,"icon_url":"https:\/\/assets.chucknorris.host\/img\/avatar\/chuck-norris.png","id":"zvno1ZJIQfetnTX5ye8TwQ","url":"https:\/\/api.chucknorris.io\/jokes\/zvno1ZJIQfetnTX5ye8TwQ","value":"The Old Spice Man aspires to smell like Chuck Norris"}

//output
{
    "category": null,
    "icon_url": "https://assets.chucknorris.host/img/avatar/chuck-norris.png",
    "id": "zvno1ZJIQfetnTX5ye8TwQ",
    "url": "https://api.chucknorris.io/jokes/zvno1ZJIQfetnTX5ye8TwQ",
    "value": "The Old Spice Man aspires to smell like Chuck Norris"
}
```
__Sorting props__

```
//input
{
    "b": 10,
    "a": 1,
    "x": {
        "foo": 1,
        "bar": 2
    }
}

//output
{
    "a": 1,
    "b": 10,
    "x": {
        "bar": 2,
        "foo": 1
    }
}
```

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