---
title: "Pretty JSON action for ActionClip"
canonical_url: "https://actionclip.app/actions/pretty-json"
document_type: "standalone_action"
official: true
action_count: 1
catalog_schema_version: 1
catalog_revision: "2026-08-21.1"
catalog_published_at: "2026-08-20T18:50:00Z"
---

# Pretty JSON action for ActionClip

Format selected JSON with readable indentation.

## What it does

Validates JSON and formats it with two-space indentation without rewriting large numeric literals or duplicate keys.

## Action details

| Field | Value |
| --- | --- |
| Category | Developer Tools |
| Action type | JavaScript |
| Result | Replace or copy text |
| Internet | Not required |

## Action and outcome

| Action | Outcome |
| --- | --- |
| **Pretty JSON** — Selected text: {"name":"ActionClip","enabled":true} | { "name": "ActionClip", "enabled": true } |

## How to format selected JSON with readable indentation with ActionClip

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

## Requirements

No setup required.

## Privacy

Runs locally in ActionClip’s JavaScript sandbox. Selected text does not leave your Mac.

## Action configuration

````javascript
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 depth = 0;
  let inString = false;
  let escaped = false;
  const indent = () => "  ".repeat(depth);
  const nextNonWhitespace = (start) => {
    for (let index = start; index < input.length; index += 1) {
      if (!/\s/.test(input[index])) return input[index];
    }
    return "";
  };

  for (let index = 0; index < input.length; index += 1) {
    const character = input[index];
    if (inString) {
      output += character;
      if (escaped) escaped = false;
      else if (character === "\\") escaped = true;
      else if (character === '"') inString = false;
      continue;
    }

    if (character === '"') {
      inString = true;
      output += character;
    } else if (character === "{" || character === "[") {
      output += character;
      const closing = character === "{" ? "}" : "]";
      if (nextNonWhitespace(index + 1) !== closing) {
        depth += 1;
        output += "\n" + indent();
      }
    } else if (character === "}" || character === "]") {
      const opening = character === "}" ? "{" : "[";
      let previous = output.length - 1;
      while (previous >= 0 && /\s/.test(output[previous])) previous -= 1;
      if (previous >= 0 && output[previous] !== opening) {
        depth = Math.max(0, depth - 1);
        output = output.replace(/\s+$/, "") + "\n" + indent();
      }
      output += character;
    } else if (character === ",") {
      output += ",\n" + indent();
    } else if (character === ":") {
      output += ": ";
    } else if (!/\s/.test(character)) {
      output += character;
    }
  }
  return output;
}
````

## Links

- [HTML listing](https://actionclip.app/actions/pretty-json)
- [Download action definition](https://actionclip.app/actions/pretty-json.actionclip)
- [Browse Developer Tools actions](https://actionclip.app/marketplace#marketplace-developerTools)
- [All Marketplace listings](https://actionclip.app/marketplace)
