New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

color-json

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-json

Color JSON in the console with no dependencies

  • 3.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Color JSON in the console with no dependencies

screenshot

Usage

Default Usage

import cj from 'color-json';

const topPlanets = [
  {
    "planet": "Saturn",
    "radius": {
      "miles": 36184
    },
    "rings": true,
    "moons": 53
  },
  {
    "planet": "Earth",
    "radius": {
      "miles": 3959
    },
    "rings": null,
    "moons": 1
  }
];

console.log(cj(topPlanets));

Switch Colors

const customColors = {
  separator: 'yellow',
  string: 'yellow',
  number: 'blue',
  boolean: 'magenta',
  null: 'red',
  key: 'green'
};
console.log(cj(topPlanets, customColors));

Customize Colors

const customColorMap = {
  black: '\x1b[38;2;0;0;0m',
  red: '\x1b[38;2;249;133;123m',
  green: '\x1b[38;2;163;238;160m',
  yellow: '\x1b[38;2;209;154;102m',
  blue: '\x1b[36m',
  magenta: '\x1b[38;2;209;154;102m',
  cyan: '\x1b[38;2;75;167;239m',
  white: '\x1b[38;2;219;223;244m'
};
console.log(cj(topPlanets, undefined, customColorMap));

Custom Spacing

console.log(cj(topPlanets, undefined, undefined, 4));

Versions

3.0.x

Converted to ESM (import instead of require).

2.x.x

Use this version if you still need require syntax (CommonJS).

Color Tool

hex to console color

Credits

user123444555621 for the syntax highlight regular expressions

Keywords

FAQs

Package last updated on 28 Feb 2023

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc