Registry / devops / json-formatter

json-formatter

JSON →
library0.1.0jsnpmunverified

A library that converts JSON data (numbers, strings, booleans, null, objects, arrays) into HTML fragments. Version 0.1.0 is the latest stable release; this is a legacy library with no active updates since 2014. It uses AMD/non-AMD patterns (Universal Module Definition). Unlike modern alternatives like JSONView or react-json-view, this library is unmaintained and lacks browser-focused features, better suited for simple server-side HTML generation from JSON.

npm install json-formatter
INSTALL
IMPORT
SIG · JSON-FORMATTER
J
json-formatter
devopsjavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JSONFormatter
import JSONFormatter from 'json-formatter'
const JSONFormatter = require('json-formatter').default
The package uses AMD/UMD. Default import works in ES modules; CommonJS may need .default.
JSONFormatter
const JSONFormatter = require('json-formatter');
const { JSONFormatter } = require('json-formatter');
For CommonJS, the entire module exports the constructor directly.
instance.toHtml
new JSONFormatter(options).toHtml(json);
JSONFormatter(options).toHtml(json);
The constructor must be called with 'new' to get an instance; missing 'new' will throw or return undefined.

Demonstrates creating a JSONFormatter instance with custom string formatting and converting a JSON object to HTML.

const JSONFormatter = require('json-formatter'); const options = { string: function(key, val) { if (key === 'id') return '<a class="link" data-request="' + val + '">' + val + '</a>'; return false; } }; const json = { id: 42, name: 'Alice', age: 30 }; const formatter = new JSONFormatter(options); const html = formatter.toHtml(json); console.log(html); // Output: <div class="object"><span class="key">id</span>: <a class="link" data-request="42">42</a>, <span class="key">name</span>: <span class="string">"Alice"</span>, <span class="key">age</span>: <span class="number">30</span></div>
Debug
Known issues
deprecatedThis library is unmaintained since 2014. No updates for security or compatibility.
fix
Consider alternatives such as react-json-view or json-viewer.
affects: >=0.1.0
gotchaThe constructor must be called with 'new'. Without new, it returns undefined and may cause errors.
fix
Always use 'new JSONFormatter(options)'.
affects: >=0.1.0
gotchaOption overrides must return false if not overriding; otherwise the default formatting is lost for that type.
fix
Return false from custom functions to fall back to default formatting.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: JSONFormatter is not a constructor
Using 'new' on a non-constructor due to wrong import or missing 'new'.
fix
Ensure you import correctly (e.g., const JSONFormatter = require('json-formatter')) and use 'new JSONFormatter(options)'.
Uncaught TypeError: Cannot read properties of undefined (reading 'toHtml')
Forgot to use 'new' when constructing the formatter; instance is undefined.
fix
Call 'new JSONFormatter(options).toHtml(json)' or assign instance: const f = new JSONFormatter(options); f.toHtml(json);
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
json-formatter — npm install json-formatter · libregistry