Structured Data Fixer — repair & normalize messy JSON/CSV/text
Under maintenancePricing
Pay per usage
Structured Data Fixer — repair & normalize messy JSON/CSV/text
Under maintenanceRepair LLM-broken JSON, strip invisible characters, dedupe rows, coerce types and validate against a JSON Schema. Deterministic rules only, no API keys, no external packages.
Pricing
Pay per usage
Rating
0.0
(0)
Developer
byd666
Maintained by CommunityActor stats
0
Bookmarked
1
Total users
0
Monthly active users
13 days ago
Last modified
Categories
Features
Share
Structured Data Fixer
Repair and normalize messy JSON, CSV, and plain text in one pass. Deterministic rules only — no LLM calls, no API keys, no network access. Zero npm dependencies: pure Node stdlib plus the Apify runtime that ships in the official base image (no npm install).
Why
LLM output and exported data are routinely almost valid: single-quoted JSON, trailing commas, Markdown fences, unquoted keys, smart quotes, invisible characters, duplicate rows, numbers stored as strings. This Actor cleans that up and tells you exactly what it changed.
Use cases
- Clean LLM output before
JSON.parse(fences, single quotes, trailing commas, unquoted keys). - Normalize exported CSV/log rows: invisible chars, whitespace, NFKC, exact-duplicate rows.
- Validate a payload against a JSON Schema and coerce
"30"→30where the schema says so.
Input
| Field | Type | Description |
|---|---|---|
content | string (required) | Raw content, max 1 MB (larger input returns INPUT_TOO_LARGE). |
contentType | auto / json / csv / text | Default auto (detect from content). |
jsonSchema | string | Optional JSON Schema; enables validation + safe type coercion. |
options | object | repairJson, stripInvisible, normalizeWhitespace, nfkc, dedupeRows, coerceTypes — all default true. |
maxPreviewItems | integer | 0–50, default 5. |
Output (dataset)
One item per run:
| Field | Description |
|---|---|
ok | false only for fatal conditions (INPUT_TOO_LARGE, unparseable JSON, invalid schema) |
error | error code when ok=false |
detectedType | json / csv / text / unknown |
cleanedText | cleaned content, ready to parse or save |
data | structured result (object/array or {rows} / {lines}) |
issues[] | what was fixed and why (JSON_SINGLE_QUOTES, JSON_TRAILING_COMMA, JSON_MARKDOWN_FENCE, JSON_UNQUOTED_KEY, INVISIBLE_CHARS, SMART_QUOTES, WHITESPACE, NFKC_NORMALIZED, DEDUPED_ROWS, TYPE_COERCED, SCHEMA_VIOLATION, JSON_PARSE_FAILED, SCHEMA_INVALID) |
warnings[] | explicitly lists heuristic guesses (e.g. "single quotes were interpreted as JSON string delimiters"). Read these before trusting the output. |
stats | inputBytes / outputBytes / removedInvisible / dedupedRows / repairedJson / coercedFields |
preview | first N structured rows |
Example
Input:
content: "```json\n{'name': 'Alice', 'age': '30', 'tags': ['a','b',], city: 'Guilin',}\n```"
Result: ok=true, repairedJson=true, cleanedText={"name":"Alice","age":"30","tags":["a","b"],"city":"Guilin"} with issues JSON_MARKDOWN_FENCE, JSON_SINGLE_QUOTES, JSON_TRAILING_COMMA, JSON_UNQUOTED_KEY and one warning per heuristic.
Honesty notes
- The Actor does not invent missing data. Unparseable JSON stays unparseable (
ok=false,JSON_PARSE_FAILED). - Heuristics (single quotes as JSON delimiters, unquoted keys, fence stripping, smart-quote normalization, dedupe) are deterministic but assumptions; every one is listed in
warnings[]. - CSV handling targets standard RFC4180; exotic dialects may need review.
- No PDF/OCR support (separate Actors cover that).
Local run
node main.js # reads apify_storage/key_value_stores/default/INPUT.json or ./INPUT.json
Sample output
{"ok": true,"error": null,"detectedType": "json","cleanedText": "{\"name\":\"Alice\",\"age\":\"30\",\"tags\":[\"a\",\"b\"],\"city\":\"Guilin\"}","data": {"name": "Alice","age": "30","tags": ["a","b"],"city": "Guilin"},"issues": [{"code": "JSON_MARKDOWN_FENCE","message": "markdown code fence stripped"},{"code": "JSON_SINGLE_QUOTES","message": "single-quoted strings converted to double quotes"},{"code": "JSON_TRAILING_COMMA","message": "trailing commas removed"},{"code": "JSON_UNQUOTED_KEY","message": "unquoted object keys quoted"}],"warnings": ["A Markdown code fence was stripped before parsing (heuristic).","Single quotes were interpreted as JSON string delimiters (heuristic).","Unquoted keys were assumed to be property names (heuristic).","Content type was auto-detected as json (starts with { or [); set contentType to make it explicit."],"stats": {"inputBytes": 79,"outputBytes": 60,"removedInvisible": 0,"dedupedRows": 0,"repairedJson": true,"coercedFields": 0},"preview": [{"name": "Alice","age": "30","tags": ["a","b"],"city": "Guilin"}]}
Privacy & data
- Runs entirely inside the Actor container: no network calls, no external APIs, no data leaves the run except the dataset you can export.
- The input is processed in memory; only the single output item is written to the dataset.
- No Apify Proxy / no full permissions needed (limited permissions).
Permissions
Limited permissions. The Actor only reads its input and writes its dataset item; it does not access the internet or your other storages.
Pricing
Free (pay-per-usage free tier). Pay-per-event pricing may be enabled later. Up to 1 MB input per run; larger inputs return INPUT_TOO_LARGE without processing.
License: MIT