3.0.1 • Published 1 year ago

json-colorizer v3.0.1

Weekly downloads
14,746
License
MIT
Repository
github
Last release
1 year ago

json-colorizer

A library for colorizing JSON strings

npm.io

This package is a simple console syntax highlighter for JSON.

Installation

npm install --save json-colorizer

Usage

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

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

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.

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.

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
erc891-minercehhgold-miner@tempicolabs/cli@infinitebrahmanuniverse/nolb-json-cjustdo@everything-registry/sub-chunk-1983find-deprecateddao3-clisvg-sass-generatorxlsx-to-couchdbxhaustsunrays@alicloud/console-toolkit-plugin-rollup@coat/clijfqironfishironfish-walletjovo-frameworkjowlipgeo-clisyzygy-visual-regressionstated-js@applied/applied-logger@autometa/cucumber-runner@admitad-tqd/feathers-rbac@admitad-tqd/tqd-lib-feathers-rbac@aeco-cloud/continuous-delivery-cra@alicloud/fun@bidipass/sdk@breezr/plugin-rollup@chec/cli0-logger@hoijnet/tuscli@designliquido/delegua-node@das.laboratory/vscode-config-interactive@congritta/http-server@controlplane/cli@cr0wst/rsnoopzf-vectrazigniswebgfx-testswebpack-config-defaultunderposttruecallerjsvectra@eastsideco/matt-cli@eastsideco/matt-cli-beta@guiferpa/aurora@hantera/cli@genexus/svg-sass-generator@kristopherpaulsen/slrp@loremlabs/send-to-social@loremlabs/setler@logzio-node-toolbox/logger@madvinking/logger@mhlabs/sfn-cli@mathquis/node-shovel@nexssp/cli@niftory/cli@exchangeunion/grpc-dynamic-gateway@migte/tplink-lightbulb-modified-version@microsoft/teams-ai@mitre/saf@kcpaulsen/slrp@jovotech/framework@jorgelg/framework@jsumners/git-user-config@dushv/jason@inferable/cli@omy.dev/omy-build-tool@olibraries/core@pubgcorp/grpc-dynamic-gateway-cors@ryantate/js-cli@saeris/tmdb-api@sangaman/grpc-dynamic-gateway@savid/logger@rf-logger/logger@pledgecamp/blockchain-utils@pioneer-platform/fio-crypto@pioneer-platform/fio-network@org-408/plantuml-parser@peopledata/minty@spot-meetings/backend-logger@softwareag/wmcc-cli@semo/core@squidcloud/coremoduloptmongodb-atlas-data-api-sdkminicaml_tsmhymhydnsyslogrclsserverless-niveshsendblocks-clinode-bmw-clientncube-thyme-typescriptnewbot-cliplayscrapeplantuml-parser
3.0.1

1 year ago

3.0.0

1 year ago

2.2.2

5 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.3

6 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.1.1

7 years ago

1.1.0

8 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago