Overview
What Minify JSON does
Removes whitespace only outside JSON strings after validation, preserving key order, duplicate keys, escape spelling, and large numeric literals exactly.
| Category | Developer Tools |
|---|---|
| Action type | JavaScript |
| Result | Replace or copy text |
| Internet | Not required |
Example
Action and outcome
| Action | Outcome |
|---|---|
| Minify JSONSelected text: { "large": 9007199254740993, "ok": true } | {"large":9007199254740993,"ok":true} |
Workflow
Use Minify JSON
Follow these steps to validate JSON and remove insignificant whitespace with ActionClip.
- Select the text you want to use.
- Choose Minify JSON from ActionClip.
- Review the result, then replace the selection or copy the new text.
Before you add it
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.
Inspect before installing
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;
}