You ask an LLM for JSON. It returns:
{
"name": "John Doe",
"email": "john@example.com",
"phone": "555-1234",
"notes": "Customer called about billing issue -- needs follow-up",
"tags": ["billing", "urgent"]
}
Looks clean. But paste it into JSON.parse() and boom:
SyntaxError: Unexpected token } in JSON at position 147
The culprit? Trailing comma after the last property. Or maybe it wrapped the whole thing in markdown code fences. Or used single quotes. Or included a comment. Or got cut off mid-token.
You reach for regex. replace(/,\s*}/g, '}') fixes trailing commas. But then you hit markdown fences. Then single quotes. Then a stray // comment. Then a truncated string. Each fix breaks something else.
There's a better way.
Why Existing Tools Fail
| Tool | Fails On |
|---|---|
| Regex | Nested objects, escaped quotes, partial truncation |
jq |
Invalid JSON (trailing commas, comments, single quotes) |
Python json.loads()
|
Strict — any violation throws |
| Online formatters | Manual copy-paste, not automatable |
| Custom Python scripts | Maintenance burden, edge cases |
The pattern: every tool assumes valid JSON. LLM output is almost JSON.
The API Approach: One Call, Pipeline of Fixes
Instead of chaining fragile fixes, define a pipeline — ordered transforms that each handle one class of mess.
curl -X POST https://textforge.co/v1/run \
-H "Content-Type: application/json" \
-d '{
"input": "{name: \"John\", email: \"john@example.com\",}",
"pipeline": ["removespecial", "removemultiple"]
}'
Response:
{
"success": true,
"input": "{name: \"John\", email: \"john@example.com\",}",
"pipeline": ["removespecial", "removemultiple"],
"result": "{\"name\": \"John\", \"email\": \"john@example.com\"}",
"steps": [
{"step": 1, "action": "removespecial", "result": "{\"name\": \"John\", \"email\": \"john@example.com\"}"},
{"step": 2, "action": "removemultiple", "result": "{\"name\": \"John\", \"email\": \"john@example.com\"}"}
],
"execution_time_ms": 3
}
Free tier: 1,000 requests/day. No API key. No account.
Top comments (0)