{"id":41335,"library":"json-formatter","title":"JSONFormatter","description":"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.","status":"deprecated","version":"0.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/iamchrismiller/JSONFormatter","tags":["javascript"],"install":[{"cmd":"npm install json-formatter","lang":"bash","label":"npm"},{"cmd":"yarn add json-formatter","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-formatter","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package uses AMD/UMD. Default import works in ES modules; CommonJS may need .default.","wrong":"const JSONFormatter = require('json-formatter').default","symbol":"JSONFormatter","correct":"import JSONFormatter from 'json-formatter'"},{"note":"For CommonJS, the entire module exports the constructor directly.","wrong":"const { JSONFormatter } = require('json-formatter');","symbol":"JSONFormatter","correct":"const JSONFormatter = require('json-formatter');"},{"note":"The constructor must be called with 'new' to get an instance; missing 'new' will throw or return undefined.","wrong":"JSONFormatter(options).toHtml(json);","symbol":"instance.toHtml","correct":"new JSONFormatter(options).toHtml(json);"}],"quickstart":{"code":"const JSONFormatter = require('json-formatter');\n\nconst options = {\n  string: function(key, val) {\n    if (key === 'id') return '<a class=\"link\" data-request=\"' + val + '\">' + val + '</a>';\n    return false;\n  }\n};\n\nconst json = { id: 42, name: 'Alice', age: 30 };\nconst formatter = new JSONFormatter(options);\nconst html = formatter.toHtml(json);\nconsole.log(html);\n// 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>","lang":"javascript","description":"Demonstrates creating a JSONFormatter instance with custom string formatting and converting a JSON object to HTML."},"warnings":[{"fix":"Consider alternatives such as react-json-view or json-viewer.","message":"This library is unmaintained since 2014. No updates for security or compatibility.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Always use 'new JSONFormatter(options)'.","message":"The constructor must be called with 'new'. Without new, it returns undefined and may cause errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Return false from custom functions to fall back to default formatting.","message":"Option overrides must return false if not overriding; otherwise the default formatting is lost for that type.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.1.0':18 '2014':34 'activ':31 'altern':44 'amd/non-amd':37 'array':13 'better':62 'boolean':10 'browser':59 'browser-focus':58 'convert':5 'data':7 'definit':41 'featur':61 'focus':60 'fragment':16 'generat':70 'html':15,69 'javascript':73 'json':6,50,72 'jsonformatt':1 'jsonview':46 'lack':57 'latest':21 'legaci':27 'librari':3,28,53 'like':45 'modern':43 'modul':40 'null':11 'number':8 'object':12 'pattern':38 'react':49 'react-json-view':48 'releas':23 'server':67 'server-sid':66 'side':68 'simpl':65 'sinc':33 'stabl':22 'string':9 'suit':63 'univers':39 'unlik':42 'unmaintain':55 'updat':32 'use':36 'version':17 'view':51","created_at":"2026-06-04T18:51:54.896774+00:00","updated_at":"2026-06-04T18:51:54.896774+00:00","problems":[{"fix":"Ensure you import correctly (e.g., const JSONFormatter = require('json-formatter')) and use 'new JSONFormatter(options)'.","cause":"Using 'new' on a non-constructor due to wrong import or missing 'new'.","error":"TypeError: JSONFormatter is not a constructor"},{"fix":"Call 'new JSONFormatter(options).toHtml(json)' or assign instance: const f = new JSONFormatter(options); f.toHtml(json);","cause":"Forgot to use 'new' when constructing the formatter; instance is undefined.","error":"Uncaught TypeError: Cannot read properties of undefined (reading 'toHtml')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"git://github.com/iamchrismiller/JSONFormatter","github":"git://github.com/iamchrismiller/JSONFormatter","docs":null,"changelog":null,"pypi":null,"npm":"json-formatter","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}