# json-chalker

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

Latest version **2.2.4** (published 2020-09-22) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2.2.4 |
| Published | 2020-09-22 |
| First published | 2020-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 14.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | ronpenton |
| Keywords | json, colorize, console |

## Links

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

## Dependencies (2)

- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.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

- 2.2.4 (latest) — 2020-09-22
- 2.2.3 — 2020-09-22
- 2.2.2 — 2020-09-15

## README

# json-chalker
A library for colorizing JSON strings, based on [json-colorizer](https://www.npmjs.com/package/json-colorizer).

This package is a simple console syntax highlighter for JSON.

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

## Usage

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

## Specifying colors

You can specify a color to use for coloring individual tokens by providing a `colors` object in the options object. This should map token types to the names of color functions (see the [chalk styles reference](https://www.npmjs.com/package/chalk#styles)).

A color can also be specified as a hex value starting with the `#` symbol.

```js
const { colorize } = require('json-chalker');
console.log(colorize({ "foo": "bar" }, {
  colors: {
    STRING_KEY: 'green',
    STRING_LITERAL: 'magenta.bold',
    NUMBER_LITERAL: '#FF0000'
  }
}));
```

The tokens available are:

* `BRACE`
* `BRACKET`
* `COLON`
* `COMMA`
* `STRING_KEY`
* `STRING_LITERAL`
* `NUMBER_LITERAL`
* `BOOLEAN_LITERAL`
* `NULL_LITERAL`

## Custom formatting

You may specify custom formatting like this:

```js
const { colorize } = require('json-chalker');
console.log(colorize({ "foo": "I'm blue", "bar": "I'm red" }, {
  colors: {
    CUSTOM: (key, value, parent) => {
        if(key == "foo") return 'blue';
        if(value == "I'm red") return 'red';
    }
  }
}));

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