Developer Tools

Minify JSON

Validate JSON and remove insignificant whitespace.

OfficialOn-device

Download action

What Minify JSON does

Removes whitespace only outside JSON strings after validation, preserving key order, duplicate keys, escape spelling, and large numeric literals exactly.

CategoryDeveloper Tools
Action typeJavaScript
ResultReplace or copy text
InternetNot required

Action and outcome

Minify JSON example
ActionOutcome
Minify JSONSelected text: { "large": 9007199254740993, "ok": true }{"large":9007199254740993,"ok":true}

Use Minify JSON

Follow these steps to validate JSON and remove insignificant whitespace with ActionClip.

  1. Select the text you want to use.
  2. Choose Minify JSON from ActionClip.
  3. Review the result, then replace the selection or copy the new text.

Requirements and privacy

  • Before you start: No setup required.
  • Your selected text: Runs locally in ActionClip’s JavaScript sandbox. Selected text does not leave your Mac.

Action configuration

The definition below is included so you can inspect how the action works before downloading it.

JavaScript definition
function run(selected_text) {
  const input = selected_text.trim();
  try {
    JSON.parse(input);
  } catch (error) {
    throw new Error("Invalid JSON: " + error.message);
  }

  let output = "";
  let inString = false;
  let escaped = false;
  for (const character of input) {
    if (inString) {
      output += character;
      if (escaped) escaped = false;
      else if (character === "\\") escaped = true;
      else if (character === '"') inString = false;
    } else if (character === '"') {
      inString = true;
      output += character;
    } else if (!/\s/.test(character)) {
      output += character;
    }
  }
  return output;
}