# json-colorizer

> A library to format JSON with colors for display in the console

Latest version **3.0.1** (published 2024-04-23) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2024-04-23 |
| First published | 2016-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 90 |
| Author | Joe Attardi |
| Maintainers | joeattardi |
| Keywords | json, colorize, console |

## Links

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

## Dependencies (1)

- [colorette](https://npm.io/package/colorette.md) ^2.0.20

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

- 3.0.1 (latest) — 2024-04-23
- 3.0.0 — 2024-04-19
- 2.2.2 — 2020-04-28
- 2.2.1 — 2019-05-08
- 2.2.0 — 2019-05-01
- 2.1.3 — 2019-05-01
- 2.1.2 — 2018-12-07
- 2.1.1 — 2018-12-05
- 2.1.0 — 2018-11-17
- 2.0.0 — 2018-11-17
- 1.1.1 — 2018-05-16
- 1.1.0 — 2017-03-01
- 1.0.2 — 2016-11-04
- 1.0.1 — 2016-10-30
- 1.0.0 — 2016-10-29

## README

# json-colorizer
A library for colorizing JSON strings

![](https://raw.githubusercontent.com/joeattardi/json-colorizer/master/screenshot.png)

This package is a simple console syntax highlighter for JSON.

## Installation
`npm install --save json-colorizer`

## Usage

```js
const { colorize } = require('json-colorizer');
console.log(colorize({ "foo": "bar" }));
```

You can also pass a JavaScript object to the `colorize` function:

```js
const { colorize } = require('json-colorizer');
console.log(colorize({
  foo: 'bar',
  baz: 42
}));
```

## Pretty-printing output

By default, the output JSON will be pretty-printed with an indentation of 2 spaces. You can adjust this by passing the `indent` option.

```js
const { colorize } = require('json-colorizer');
console.log(colorize({
  foo: 'bar',
  baz: 42
}, { indent: 4 }));
```

## Customizing the colors

You can override any of the colors used for token types by providing a `colors` option. This should map token types to the names of color functions. These color functions are contained in the `color` object exported by the library.

```js
const { colorize, color } = require('json-colorizer');

console.log(colorize({ foo: 'bar' }, {
  colors: {
    StringLiteral: color.red
  }
}));
```

The list of valid token types and color functions are listed below.

### Token types

- `Brace`: curly braces (`{`, `}`)
- `Bracket`: square brackets (`[`, `]`)
- `Colon`: colon character (`:`)
- `Comma`: comma character (`,`)
- `StringKey`: the key in a key/value pair
- `NumberLiteral`: a number value
- `StringLiteral`: a string value
- `BooleanLiteral`: a boolean literal (`true`, `false`)
- `NullLiteral`: the literal `null` value

### Color functions in the `color` object

- `black`
- `red`
- `green`
- `yellow`
- `blue`
- `magenta`
- `cyan`
- `white`
- `gray`

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