Zapier JSON Formatter: Fix Parse Errors and Handle Malformed JSON in Your Zaps
Zapier JSON parsing failing? Learn how to format, repair, and validate JSON in Zapier workflows with Code steps and the Formatter app.
Have broken JSON right now? Fix it free in under 1 second — no signup.
Fix My JSON →Zapier is the glue between your apps — but when JSON breaks in the middle of a workflow, the whole Zap stops dead. Whether you're pulling JSON from an API, processing AI-generated output, or passing structured data between steps, a single malformed character can halt your automation. This guide explains how Zapier handles JSON, why it fails, and exactly how to fix every common parse error.
How Zapier Handles JSON
Zapier's JSON handling works on two layers:
Automatic parsing: When a Trigger or Action step returns a response withContent-Type: application/json, Zapier automatically parses the body and makes individual fields available as variables in subsequent steps. You see Output > name, Output > email, etc. — you never write a single line of code.
Manual parsing: When JSON arrives as a raw string — inside a field value, as a webhook body without the right content-type header, or as the output of a text-based AI step — Zapier treats it as a string. You need to explicitly parse it to access the fields inside.
This distinction matters. If your Zap is failing, the first question is: is Zapier getting a parsed object or a raw JSON string?
Why Zapier JSON Parsing Fails
Most Zapier JSON failures come from a handful of sources:
Trailing Commas
JSON specification prohibits trailing commas. JavaScript allows them; JSON does not. AI tools frequently produce trailing commas.
// Invalid JSON — will crash Zapier's JSON parser
{
"name": "Alice",
"status": "active",
}
Python-Style Boolean and Null Values
If your Zap includes an OpenAI or Anthropic step, the model may output Python-style values instead of JSON-compliant ones:
// Invalid JSON
{
"active": True,
"deleted": False,
"metadata": None
}
JSON requires true, false, and null (lowercase). True, False, and None are Python literals and will cause an immediate parse failure.
Single Quotes
Python and JavaScript template strings often use single quotes. JSON requires double quotes for all strings and keys.
// Invalid JSON
{'name': 'Alice', 'role': 'admin'}
Markdown Code Fences
If your Zap routes through an AI step that returns a code block, the output might be:
json
{"name": "Alice"}
The backticks are Markdown syntax — they're not valid JSON and will cause a parse error.
Unquoted Keys
Some serializers and AI models produce JavaScript object notation instead of strict JSON:
// Invalid JSON
{name: "Alice", role: "admin"}
Using Zapier Formatter > Utilities > Format JSON
For simple formatting needs — pretty-printing a compact JSON string — Zapier's built-in Formatter action handles it cleanly:
- Add a Formatter by Zapier step
- Choose Utilities as the transform type
- Choose Format JSON as the transform
- Map the field containing your JSON string to the input
- The output is a formatted, indented JSON string
For broken JSON, you need a Code step.
Using a Code Step to Repair JSON
Zapier's Code by Zapier step (available on paid plans) lets you run JavaScript to repair malformed JSON before parsing it. Here is a robust repair function you can paste directly into a Zapier Code step:
// Input: inputData.raw_json — the broken JSON string from a previous step
const rawJson = inputData.raw_json;
function repairJson(input) {
let s = input;
// 1. Strip markdown code fences
s = s.replace(/^
(?:json)?\s/i, "").replace(/\s```\s*$/, "");
// 2. Replace Python booleans and null
s = s.replace(/\bTrue\b/g, "true");
s = s.replace(/\bFalse\b/g, "false");
s = s.replace(/\bNone\b/g, "null");
// 3. Convert single-quoted strings to double-quoted
// This is a simplified approach — handles the common case
s = s.replace(/([{,\[]\s)'([^']+)'\s:/g, '$1"$2":');
s = s.replace(/:\s'([^'])'/g, ': "$1"');
// 4. Remove trailing commas before ] or }
s = s.replace(/,\s*([\]}])/g, "$1");
return s;
}
const repaired = repairJson(rawJson);
// Try to parse — throw a clear error if still invalid
let parsed;
try {
parsed = JSON.parse(repaired);
} catch (e) {
throw new Error(JSON repair failed: ${e.message}. Input was: ${rawJson.slice(0, 200)});
}
// Return fields you need in subsequent steps
output = {
repaired_json: repaired,
// Spread top-level fields if it's an object
...(typeof parsed === "object" && !Array.isArray(parsed) ? parsed : { data: parsed }),
};
How to connect this in your Zap:
- Add a Code by Zapier step (JavaScript)
- Map the broken JSON string to an input variable named
raw_json - Paste the function above
- In the next step, use
Output > repaired_json (or the individual fields)
Connecting AI Tool Outputs to Zapier
ChatGPT, Claude, and similar AI steps in Zapier often return structured JSON inside a text response. The model is prompted to return JSON but the output field is a plain string — sometimes with extra prose around it.
A robust pattern for AI-to-JSON in Zapier:
Step 1: AI Action (e.g. OpenAI GPT-4)
- Prompt: "Return ONLY valid JSON with no markdown, no explanation. Format:
{"name": string, "score": number}" - Output field:
choices[0].message.content — this is your raw string
Step 2: Code by Zapier — run the repair function above against the AI output
Step 3: Formatter by Zapier > Utilities > Format JSON — optional, for human-readable output in later steps
Step 4: Your downstream action — uses the parsed fields
The key insight is that even well-prompted AI models occasionally add a leading explanation or a trailing comment. The repair step catches these edge cases so your Zap doesn't break on the 1-in-50 response that doesn't conform perfectly.
Validating JSON Before Building Scenarios
Before wiring up a Zap end-to-end, it pays to verify that your JSON source produces valid output. Paste sample responses from the API or AI tool into the JSON Validator — it gives you a precise error location and description, so you know exactly what your repair step needs to handle.
If the JSON has structural errors, AI JSONMedic repairs it automatically and shows a diff of every change. Paste a few real samples, run the fixer, and look at the repair report. That tells you which transforms to include in your Code step — you're not guessing, you're targeting known failure modes.
For pretty-printing minified JSON from a webhook, the JSON Formatter tool is the fastest way to make it human-readable before studying its structure.
Common Zapier JSON Error Messages and Fixes
Error message Root cause Fix Unexpected token T in JSON at position 0Python True at start of value Replace True/False/None with true/false/null Unexpected token ' in JSON at position 0Single-quoted string Convert single quotes to double quotes Unexpected token < in JSON at position 0HTML error page returned instead of JSON Check the API step — it's returning an error page Unexpected token } in JSON at position NTrailing comma before } Remove trailing commas Unexpected end of JSON inputTruncated JSON string JSON was cut off — check the field size limit in the previous step JSON parse error: Cannot read property of undefinedField doesn't exist in parsed object The JSON parsed successfully but the key path is wrong — check field mapping
A Note on Zapier's Field Size Limits
Zapier truncates field values longer than 65,536 characters (64 KB). If you're passing large JSON objects through a Zap — for example, an AI step returning a large structured document — the JSON may arrive truncated at exactly 65,536 characters, producing an Unexpected end of JSON input error.
If you hit this limit, the fix is architectural: don't pass large JSON as a field value. Instead, write the data to a Google Sheet, Airtable, or S3 bucket in one step, and read it back in another.
Summary
Zapier JSON parsing fails for predictable reasons: AI-generated output with Python literals or markdown fences, single-quoted strings from non-standard serializers, and trailing commas are the top three. The fix is a Code step with a targeted repair function that runs before any step that needs to parse the JSON.
Use the JSON Validator to diagnose exactly what's breaking, and AI JSONMedic to repair samples and inspect the changes — that combination tells you precisely what your Code step needs to handle, so you build the repair once and it works reliably on every run.
FAQ
How do I parse JSON in a Zapier workflow?
Use Zapier's built-in "Formatter" action → "Utilities" → "Line Itemizer" for simple arrays. For complex JSON, use a Code step (JavaScript or Python): const data = JSON.parse(inputData.raw_json); return { name: data.name, email: data.email };. The Code step gives you full control over parsing and field extraction.
Why does Zapier's Code step fail to parse AI-generated JSON?
AI models output Python-style literals: True, False, None instead of true, false, null. Zapier's JavaScript Code step doesn't understand these. Fix before parsing: const clean = raw.replace(/True/g,'true').replace(/False/g,'false').replace(/None/g,'null').replace(/
json\n?/g,'').replace(/`/g,''); const data = JSON.parse(clean);.
Can I validate JSON format in Zapier before it reaches downstream steps?
Yes — use a Code step with a try/catch and use Zapier's "Filter" step on a valid field: try { JSON.parse(inputData.json); output = [{valid: 'true'}]; } catch(e) { output = [{valid: 'false', error: e.message}]; }. The Filter step only continues the Zap when valid === 'true', preventing invalid JSON from reaching steps that would fail silently.
How do I extract nested fields from JSON in Zapier without a Code step?
Use Zapier's "Formatter" action → "Text" → "Extract Pattern" with a regex to pull specific values. For simple nested JSON like {"user": {"name": "Alice"}}, you can sometimes use Zapier's built-in field mapping if the webhook/API step returns the nested structure directly. For reliable extraction of complex nesting, a Code step is more maintainable.
What is the fastest way to fix a broken JSON Zap without rebuilding it?
Add a Code step immediately before the failing step. Copy the exact input the failing step receives (visible in the Zap History under "Input"), repair it in the Code step (fix Python literals, strip markdown fences, handle trailing commas), and pass the clean JSON forward. You don't need to rebuild the Zap — just intercept and fix in-flight.
Still dealing with broken JSON?
Paste it in and get it fixed in under 1 second — free, no signup, no install. Works with ChatGPT, Claude, n8n, and any AI output.
Fix My JSON Free →Related Articles