
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
color-json
Advanced tools
The color-json npm package is designed to enhance the readability of JSON data by adding color to the output. This is particularly useful for developers who need to quickly parse and understand JSON structures in a visually appealing way.
Colorize JSON
This feature allows you to colorize JSON data for better readability in the console. The code sample demonstrates how to use the color-json package to print a JSON object with colorized output.
const colorJson = require('color-json');
const jsonData = {
name: "John Doe",
age: 30,
city: "New York"
};
console.log(colorJson(jsonData));
The json-colorizer package provides similar functionality by adding color to JSON strings for improved readability. It offers customization options for colors and styles, which can be more flexible compared to color-json.
Prettyjson is another package that formats and colorizes JSON data. It focuses on making JSON output more human-readable with indentation and color, similar to color-json, but also includes additional formatting options.
Cli-color is a more general-purpose package for adding color to console output, including JSON. While it doesn't specifically target JSON, it can be used to achieve similar results by manually applying color to JSON strings.
Color JSON in the console with no dependencies
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));
const customColors = {
separator: 'yellow',
string: 'yellow',
number: 'blue',
boolean: 'magenta',
null: 'red',
key: 'green'
};
console.log(cj(topPlanets, customColors));
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));
console.log(cj(topPlanets, undefined, undefined, 4));
Converted to ESM (import
instead of require
).
Use this version if you still need require
syntax (CommonJS).
user123444555621 for the syntax highlight regular expressions
FAQs
Color JSON in the console with no dependencies
The npm package color-json receives a total of 144,654 weekly downloads. As such, color-json popularity was classified as popular.
We found that color-json demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.