Skip to content

JSON Minify — TypeScript source

Remove all whitespace from JSON for the most compact serialization. Validates as it minifies, runs entirely in your browser, with a shareable link to your exact input.

This is the TypeScript implementation — the same logic the interactive tool runs, in a shareable, citable form.

// Pure JSON minifier - parses then re-serializes with no whitespace. Zero deps
// - the unit-test surface for the JSON Minify tool.

/** Compact JSON serialization of `input`, or null if it is not valid JSON. */
export function minifyJson(input: string): string | null {
  try {
    return JSON.stringify(JSON.parse(input));
  } catch {
    return null;
  }
}

Also available in 13 other languages

Every CosmoDev tool ships its pure logic in TypeScript (web) and Go (CLI), with authored implementations in a dozen-plus languages — the same contract, ported. Compare all languages side by side →