Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
json-lighter
Advanced tools
A lightweight JSON syntax highlighter for the web.
npm install json-lighter
import { JsonLighter } from "json-lighter";
const lighter = new JsonLighter({
spaces: 2,
colors: {
punctuation: "gray",
string: "orange",
number: "green",
boolean: "purple",
null: "blue",
},
});
// Inject the CSS into the document
lighter.injectCSS();
// Highlight JSON
const html = lighter.highlight(`
{
"string": "value",
"number": 123.123,
"boolean": false,
"null": null
}
`);
## API
### `JsonLighter(options)`
Creates a new instance of JsonLighter.
#### Options
- `spaces` (number): Number of spaces for indentation.
- `colors` (object): Custom colors for different JSON elements
- `punctuation` (string): Color for punctuation characters
- `string` (string): Color for string values
- `number` (string): Color for number values
- `boolean` (string): Color for boolean values
- `null` (string): Color for null values
### `lighter.injectCSS()`
Injects the necessary CSS into the document's head. Call this once before using the `highlight` method.
### `lighter.highlight(json)`
Highlights the provided JSON string and returns HTML with syntax highlighting.
#### Parameters
- `json` (string): The JSON string to highlight
#### Returns
- (string): HTML string with syntax highlighting
FAQs
A lightweight JSON syntax highlighter for the web.
The npm package json-lighter receives a total of 0 weekly downloads. As such, json-lighter popularity was classified as not popular.
We found that json-lighter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.