A restify formatter that unicode-escapes <, >, and & characters in JSON responses as \u003c, \u003e, and \u0026 respectively, preventing browsers from interpreting JSON as HTML. Version 0.4.10 is the latest release, last updated in 2018. It requires Node.js >=10 and npm >=6.4.1. This package is a lightweight alternative to manually escaping JSON for XSS prevention, specifically designed for Restify servers.
npm install restify-safe-json-formatterNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a Restify server using safeJsonFormatter to escape HTML-like characters in JSON responses.
If full JSON escaping is needed, consider using a more comprehensive serializer.
Use res.json() which sets Content-Type to application/json by default.
Check Restify v10+ compatibility; consider using restify's built-in formatter or a custom one.
In Restify <10, wrap the return value in Buffer.from() if needed.
Use const safeJsonFormatter = require('restify-safe-json-formatter') or import safeJsonFormatter from 'restify-safe-json-formatter'.Set formatters key to 'application/json' or use res.json() which sets Content-Type automatically.
Do not use safeJsonFormatter if clients need raw JSON; use restify's default JSON formatter.