Socket
Book a DemoInstallSign in
Socket

json-chalker

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-chalker

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

2.2.4
latest
Source
npmnpm
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

json-chalker

A library for colorizing JSON strings, based on json-colorizer.

This package is a simple console syntax highlighter for JSON.

Installation

npm install --save json-chalker

Usage

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).

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

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:

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';
    }
  }
}));

Keywords

json

FAQs

Package last updated on 22 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.