Starting points for your own code. Run them in the environment shown below.
Node.js 22+ · ES module (.mjs)
Current inputs apply only to fields used by the example. Selected files are not embedded.
Install dependencies
npm install html-entities
import { encode, decode } from "html-entities";
const input = "Hello \"world\"\n<hello>";
const mode = "escape";
const format = "json";
let output;
if (format === "html") output = mode === "escape" ? encode(input, { mode: "specialChars" }) : decode(input);
else {
output = mode === "escape" ? JSON.stringify(input) : JSON.parse(input);
if (typeof output !== "string") throw new Error("Expected a quoted string");
}
console.log(output);
Put it to work
Convert JSON/JavaScript strings and HTML entities.
Details that matter
Format and meaning
JSON/JavaScript uses JSON-compatible double-quoted strings. Input is never executed as code.
Supported scope and limits
Text 1 MB
Split inputs that exceed the limit. If a format or algorithm is unsupported, choose a tool that matches your requirements instead of silently changing the format.