Prompt Cleaner
Free in-browser AI text cleaner and JSON escape fixer
Clean messy ChatGPT, Claude, Gemini, and Perplexity output in seconds. Fix broken JSON, strip emojis and zero-width unicode, normalize smart quotes, convert prompts to one line, and count tokens. Everything runs in your browser.
Cleaning options
Toggle individual transformationsAI Prompt Cleaner
Strip the artifacts AI models leave behind: zero-width unicode, smart quotes, double-encoded newlines, and stray whitespace.
One-Line Converter
Collapse a multi-line ChatGPT or Claude prompt into a single line for chat inputs, JSON fields, and YAML flow scalars.
AI Text Beautifier
Trim each line, collapse blank lines, normalize quotes, and remove invisible characters for clean handoff to teammates.
JSON Formatter and Fixer
Pretty-print AI-generated JSON with soft auto-repair for trailing commas, single quotes, and smart quotes from chat exports.
Escape and Unescape
Convert real line breaks and quotes into \n and \" for embedding in JSON payloads. Reverse it to read API responses cleanly.
Token Estimator
Approximate token count using the GPT-4 family heuristic (~4 chars/token). Budget your context window before paying for the call.
How to clean AI prompts and messy text
Paste any AI output, pick a cleaning mode, and copy the result. Every transformation runs locally in your browser, so prompts never touch a server.
Paste your messy AI text
Drop in a ChatGPT response, a Claude answer, a Gemini reply, a Midjourney prompt, or busted JSON from an API call. Or load a sample with one click.
Pick Soft or Aggressive
Clean (Soft) preserves your formatting and only fixes invisible artifacts. Aggressive Clean rips out line breaks, markdown, emojis, and quotes in one click for an API-ready prompt.
Copy or download
Grab the cleaned prompt as plain text, as an escaped JSON string, or download a .txt or .json file. Everything happens client-side with no upload step.
What Is a Prompt Cleaner?
A Prompt Cleaner is a free utility that fixes messy AI text. It takes the kind of output you get from ChatGPT, Claude, Gemini, Perplexity, or any LLM API, and normalizes it into a clean string you can paste anywhere. The cleaning passes include removing line breaks, fixing JSON escape characters, stripping markdown, deleting zero-width unicode, normalizing smart quotes, and trimming whitespace.
Anyone working with large language models needs a Prompt Cleaner. Developers building with the OpenAI, Anthropic, or Gemini APIs deal with messy strings every day. Prompt engineers maintain libraries of prompts that need consistent formatting. Marketers paste AI-generated copy into CMS fields and Slack messages that mangle unicode. A Prompt Cleaner takes care of the formatting work so you can focus on the content.
Our Prompt Cleaner runs entirely in your browser. There is no server, no API call, no logging. The cleaning logic is plain JavaScript that executes on your device. That matters because the prompts you clean often contain proprietary instructions, customer data, or unreleased product ideas. You should not paste those into a tool that ships them off to a third party.
The 6 Most Common Problems in AI Text
These are the issues that show up over and over in ChatGPT, Claude, Gemini, and API output. Each one is fixable in one click with the Prompt Cleaner.
Random line breaks
AI models love to wrap output across multiple lines, even when you ask for a single sentence. When you paste that into a chat input that submits on enter, you end up sending half-finished messages. The One-Line Converter joins everything into a single line with a single space between words.
Escape sequences in JSON
When an API returns a JSON response, string fields contain escape sequences like \n for newline, \t for tab, \" for double quote, and \\ for backslash. To read the content as a human, you need to convert those back to real characters. Unescape does that. Going the other way (Escape) is useful when you need to put a multi-line prompt inside a JSON string field.
Smart quotes from chat exports
Curly quotes and apostrophes look identical to straight quotes on screen, but they break string comparisons, regex patterns, and JSON parsing. AI chat interfaces often render quotes as smart quotes. When you copy that text into code, your equality checks fail silently. Normalize smart quotes converts them all to straight ASCII quotes.
Zero-width unicode characters
AI output sometimes contains invisible unicode like zero-width space (U+200B), zero-width joiner (U+200D), or the byte order mark (U+FEFF). You cannot see them, but they break deduplication, search, and string equality. They are also one of the known ways AI text gets watermarked. The Prompt Cleaner removes them by default.
Markdown syntax mixed in with prose
Chat assistants format responses with bold, italics, headings, and code fences. When you paste that into a CMS that does not render markdown, you get **literal asterisks** all over your copy. Strip markdown removes the syntax while keeping the actual words.
Double-encoded JSON
When an AI returns JSON inside a JSON string field, you end up with backslashes everywhere. The cleanup is two passes: unescape to convert \\n back to \n, then JSON Formatter to parse and pretty-print the inner JSON. The Prompt Cleaner handles both in a couple of clicks.
Remove Line Breaks vs One-Line Converter vs JSON Formatter
Three nearby buttons. Different jobs. Here is when to use each one.
| Tool | What it does | Use when |
|---|---|---|
| Remove line breaks | Strips every newline from the text and collapses extra spaces. | Quick fix when you have a multi-line response and need a single-line string for a CSV cell or chat input. |
| One-Line Converter | Removes line breaks and applies the rest of your active cleaning options in one shot. | Best for prepping a prompt for an API call where you want a fully normalized single-line string. |
| JSON Formatter | Parses your input as JSON (with soft auto-repair) and pretty-prints it with 2-space indentation. | When an API or AI returned JSON and you want to read it or share it with a teammate. |
| Escape | Converts real \n, \", and backslashes into their escape sequences. | Embedding a multi-line prompt inside a JSON string field or a code string literal. |
| Unescape | Converts \n, \", \uXXXX back into real characters. | Reading the actual content of a JSON string field from an API response. |
| Aggressive Clean | Applies every cleaning pass at once: line breaks, markdown, emojis, smart quotes, double quotes, zero-width chars. | You want a single-line, ASCII-friendly, no-formatting prompt ready to ship to an API or share in plain text. |
Why Escape Characters Break JSON
JSON strings have strict rules. A raw newline inside a string value is illegal. A raw tab is illegal. An unescaped double quote inside a string ends the string early. A bare backslash followed by anything other than a valid escape is illegal. When an AI returns text with any of those characters and you try to embed it inside a JSON request body, the parser rejects the whole payload.
The fix is escape sequences. A newline becomes \n. A tab becomes \t. A double quote becomes \". A backslash becomes \\. Once every special character is properly escaped, the JSON is valid and the API can parse it. The Prompt Cleaner Escape button does this for you in one click.
Going the other direction is just as common. You get an API response with a string field that contains \n everywhere. To read it as a human, you need to convert the escape sequences back to real characters. Unescape does that. If you also need the underlying content to be parsed as JSON (because the AI returned JSON inside a string field), follow up with JSON Formatter.
How Tokenization Works (and Why It Costs You Money)
Large language models do not read characters. They read tokens. A token is a chunk of text that the tokenizer treats as a single unit. For GPT-4 and GPT-4 Turbo using the cl100k_base tokenizer, common English words are usually one token. Less common words split into 2 or 3 tokens. Punctuation, whitespace, and unicode characters often use their own tokens. The rule of thumb is roughly 4 characters per token for typical English text.
Tokens map directly to cost. OpenAI, Anthropic, and Google all charge per million input tokens and per million output tokens. A prompt that is 4,000 characters is roughly 1,000 tokens. At a $5-per-million input rate, that prompt costs half a cent before the model writes a single token of response. If you are running thousands of prompts per day, cleanup matters.
Cleaning a prompt also reduces tokens. Removing zero-width characters, collapsing multi-spaces, trimming each line, and stripping markdown all reduce the character count without changing the meaning. A 10% reduction in tokens is a 10% reduction in cost. The token counter in the Prompt Cleaner shows you exactly how much you trimmed.
The token estimate in this tool uses the standard 4-chars-per-token heuristic. It is approximate. For exact counts, use the official tokenizers from OpenAI (tiktoken) or Anthropic. For quick budgeting and "will this fit in a 128k context window" checks, the estimate is reliable enough.
Why In-Browser Processing Matters
Prompts often contain things you do not want a third party to see. Internal strategy. Customer support transcripts. Unreleased product names. Source code. PII. When you paste that text into a website to "clean" it, you have no way to know whether the site logs your input, ships it to an analytics provider, trains a model on it, or stores it in a database.
The Prompt Cleaner runs entirely in your browser. There is no upload step. The cleaning logic is plain JavaScript that executes on your machine. You can verify this by opening the network tab in your browser DevTools and watching for outgoing requests while you clean. You will see none.
Because everything is client-side, the tool also works offline after the first page load. You can clean prompts on an airplane, in a SCIF, on an air-gapped workstation, or anywhere else your laptop happens to be without an internet connection.
The full feature set, including JSON parsing, regex-based cleanup, escape conversion, and token estimation, runs in pure JavaScript with no external dependencies and no API keys. If you want to audit the logic, view source on this page.
Who Uses a Prompt Cleaner
Four groups get the most value out of a Prompt Cleaner. The use cases overlap but the priorities are different.
Developers building with LLM APIs
Prep prompts that need to be embedded in JSON request bodies. Clean API responses for downstream processing. Strip escape characters before logging.
Prompt engineers
Normalize prompts across teams and version control them cleanly. Detokenize for analysis. Spot zero-width watermarks that change prompt behavior.
Marketers and content teams
Clean AI-generated blog drafts before pasting into a CMS. Strip emojis and markdown for plain-text email broadcasts. Normalize quotes for brand consistency.
Researchers and analysts
Prep AI output for deduplication, sentiment analysis, or feeding into another pipeline. Reduce token counts before paying for embeddings.
Quick Reference: Every Escape Sequence
The Prompt Cleaner handles every standard escape sequence in both directions. Here is the full reference.
| Escape | Real character | Where you see it |
|---|---|---|
| \n | newline | Multi-line strings inside JSON. Most common AI output issue. |
| \r | carriage return | Windows line endings. Often paired with \n. |
| \t | tab | Indented code or formatted tables in AI output. |
| \b | backspace | Rare. Sometimes shows up in poorly formatted ANSI sequences. |
| \f | form feed | Very rare. Legacy printer control character. |
| \" | double quote | Quoted dialog or product names inside JSON string fields. |
| \' | single quote | Some non-JSON formats. JSON does not require escaping single quotes. |
| \\ | backslash | File paths on Windows. Regex patterns inside strings. |
| \/ | forward slash | Optional in JSON. Used for embedding in HTML script tags. |
| \uXXXX | unicode codepoint | Non-ASCII characters in restricted JSON. Hex digits XXXX. |
Prompt Cleaner questions answered
Everything you need to know about cleaning AI prompts, fixing JSON escape characters, removing zero-width unicode, and counting tokens.
A Prompt Cleaner is a free tool that fixes messy AI text. It removes line breaks, strips escape characters (\n, \t, \", \\), normalizes smart quotes, deletes zero-width unicode characters, beautifies broken JSON, and trims extra whitespace. Devs, prompt engineers, marketers, and content teams use it to prep AI prompts for APIs, paste clean output into other tools, or share readable text with teammates. Everything runs in your browser, so prompts never leave your device.
Yes. The Prompt Cleaner is 100% free with no signup, no login, no email gate, and no usage limits. Clean as many prompts as you want. There is no paid tier and no upsell inside the tool. We offer it as a free utility from KeyGrow, a marketing agency that helps brands rank on Google and AI search engines.
No. The Prompt Cleaner runs entirely in your browser using client-side JavaScript. Your text never touches our servers, never gets logged, and never gets sent over the network. You can verify this by opening your browser DevTools network tab while pasting and cleaning. Cleaning happens locally on your device, so the tool also works offline after the first page load.
The Prompt Cleaner can unescape every standard JSON and string escape sequence: \n (newline), \r (carriage return), \t (tab), \b (backspace), \f (form feed), \" (escaped double quote), \\ (escaped backslash), \/ (escaped forward slash), and \uXXXX unicode escapes like \u00A0 for non-breaking spaces. The opposite Escape mode adds these back when you need to embed cleaned text inside a JSON string.
Yes. The One-Line Converter mode joins every line of your prompt into a single line, replacing line breaks with a single space and collapsing multiple spaces. This is useful when you need to paste a prompt into a chat input that does not handle line breaks well, embed it inside a JSON string field, or include it in a YAML config that needs flow style. The tool preserves words and punctuation while removing only whitespace artifacts.
Yes. The JSON Formatter button attempts to parse and pretty-print AI-generated JSON. If the JSON has common AI mistakes like trailing commas, single quotes around keys, smart quotes, or unescaped newlines inside strings, the tool runs a soft repair pass before parsing. Once parsed, it pretty-prints with 2-space indentation and shows a JSON valid badge. If the JSON cannot be repaired automatically, the tool highlights the parse error so you can fix it manually.
Clean (Soft) applies the minimum safe transformations: trim leading and trailing whitespace, collapse multiple consecutive spaces into one, remove zero-width unicode characters, and normalize line endings. It preserves your original formatting and structure. Aggressive Clean adds more transformations: removes all line breaks, strips markdown syntax (** __ ` # > [text](url)), removes emojis and special unicode symbols, removes double quotes, and normalizes smart quotes to straight quotes. Use Soft when you want readable text. Use Aggressive when you need a clean single-string prompt for an API call.
Yes. Toggle the Remove emojis and special characters option, and the Prompt Cleaner strips every emoji (including multi-codepoint emojis with ZWJ sequences), pictographs, dingbats, regional indicators, and most non-ASCII symbols while preserving normal letters, digits, punctuation, and accented Latin characters. This is the cleanest way to prep marketing prompts that an AI returned with emoji garnishes for downstream tools that do not handle unicode well.
The token estimate uses the standard heuristic of roughly 4 characters per token, which approximates the GPT-4 family tokenizer (cl100k_base) for typical English text. The estimate is within about 10% of the real token count for most prompts. It can drift further for code, JSON, non-English text, or text with many short words. For exact counts, paste your cleaned prompt into the official OpenAI or Anthropic tokenizer. For quick budgeting and "will this fit in context" checks, the estimate is reliable enough.
Yes, after the first page load. The entire tool is a single page of JavaScript that runs in your browser, with no API calls and no server dependencies. Once the page is cached by your browser, you can disconnect from the internet and the cleaner will keep working. This is useful for cleaning sensitive prompts on air-gapped machines, on planes, or in low-bandwidth environments where you do not want to round-trip text to a server.
Yes. Midjourney prompts often arrive with line breaks, emojis, smart quotes, and markdown formatting copied from chat exports. Use Aggressive Clean to collapse the prompt into a single line with no markdown, no emojis, and straight quotes. The result is a clean prompt string ready to paste into the Midjourney bot or any other image model. The same workflow works for Stable Diffusion, DALL-E, Flux, and any other prompt-driven image tool.
Yes. Enable Strip markdown and the tool removes bold (**text** and __text__), italic (*text* and _text_), headings (# ## ###), inline code (`code`), code fences (```), blockquotes (>), and markdown links ([text](url) becomes just text). It preserves the underlying words and punctuation. This is useful when an AI returns a richly formatted answer and you need plain prose for a downstream system that does not render markdown.
Zero-width characters are invisible unicode characters like zero-width space (U+200B), zero-width joiner (U+200D), zero-width non-joiner (U+200C), word joiner (U+2060), and the byte order mark (U+FEFF). They take up no visible space but they are real characters. AI outputs sometimes contain them, and they can break string comparisons, regex patterns, deduplication, and search indexing. They are also a known watermarking technique for AI text. The Prompt Cleaner removes them all by default.
Yes. The tool is fully responsive and works on phones and tablets. The input and output panes stack vertically on small screens, and all buttons are touch-friendly. Copy and download buttons use the native browser APIs, so they work in mobile Safari, Chrome, and Firefox without any plugins. For long prompts, a desktop browser is more comfortable, but mobile works for quick cleanups on the go.
Yes, with a workaround. Paste all your prompts into the input pane with a clear separator between them (a blank line, three dashes, or any unique marker). Apply your cleaning settings. The output will be your separator-delimited cleaned prompts ready to split downstream. For true batch processing of hundreds of prompts, you can copy the cleaning logic from the tool (it is plain JavaScript) and run it in a script. The Prompt Cleaner is designed primarily for interactive single-prompt cleanup.
The Prompt Cleaner offers three export options. Copy Cleaned Text copies the output to your clipboard as plain text. Copy as JSON String copies the output with all special characters properly escaped, ready to paste inside a JSON value. Download .txt saves the cleaned text as a plain text file. Download .json saves the cleaned text as a properly escaped JSON string inside a file. All downloads happen client-side using a Blob and an in-browser link, with no server round-trip.
Four main groups use Prompt Cleaners. Developers building with LLM APIs use it to prep prompts that need to be embedded in JSON requests or sent over HTTP. Prompt engineers use it to normalize prompts across teams and version-control them cleanly. Marketers and content teams use it to clean AI-generated copy before pasting it into a CMS or social tool. Researchers and analysts use it to prep AI output for analysis, deduplication, or feeding into another pipeline.
Your prompts are clean. Is your brand?
Our team helps SaaS, agency, and e-commerce brands show up on Google search and inside answers from ChatGPT, Claude, Gemini, and Perplexity. Free audit, no obligation.
Get Free Growth AuditYour prompts are clean. Is your brand showing up in AI search?
Buyers ask ChatGPT, Claude, Gemini, and Perplexity for recommendations every day. We help brands rank inside those answers and on Google search with AEO, SEO, and content built for the AI era.
AI Search Optimization (AEO)
Get cited inside answers from ChatGPT, Claude, Gemini, and Perplexity. Schema, entity coverage, and content built to be quoted.
SEO and Content Strategy
Keyword research, topical authority, and content that ranks on Google. From the keyword brief to the published page.
Conversion-Built Pages
Landing pages, service pages, and blog content built to rank and convert. Clear copy, fast load, structured for AI parsing.