AykutSarac/jsoncrack.com · error
json, error
Error message
json, error
What it means
Logged by jsonToContent when serializing parsed JSON into YAML/XML/CSV. console.error(json, error) dumps the entire payload plus the error. Sources include JSON.parse(json) throwing on malformed input, js-yaml dump failing on circular/non-serializable values, fast-xml-parser build rejecting certain value types, or json-2-csv json2csv rejecting arrays whose elements have incompatible shapes. The function returns the original json string as a fallback so the user keeps data but sees no conversion.
Source
Thrown at apps/www/src/lib/utils/jsonAdapter.ts:90
if (format === FileFormat.CSV) {
const { json2csv } = await import("json-2-csv");
const parsedJson = JSON.parse(json);
const data = Array.isArray(parsedJson) ? parsedJson : [parsedJson];
return json2csv(data, {
expandArrayObjects: true,
expandNestedObjects: true,
excelBOM: true,
wrapBooleans: true,
trimFieldValues: true,
trimHeaderFields: true,
});
}
return json;
} catch (error) {
console.error(json, error);
return json;
}
};
View on GitHub (pinned to 3c9af69e23)
Solutions
- Validate JSON.parse(json) succeeds before branching on format.
- For CSV, pre-flatten or reject arrays whose elements have incompatible shapes before calling json2csv.
- Pass a replacer/nullChecker to js-yaml or json-2-csv to handle non-serializable values.
- Stop logging the entire json payload — log json.length or a hash to avoid dumping large data to the console.
Example fix
// before
} catch (error) {
console.error(json, error);
return json;
}
// after
} catch (error) {
console.error("jsonToContent failed for format", format, "len", json.length, error);
return json;
} Defensive patterns
Strategy: validation
Validate before calling
// Validate before converting
function isSerializableForFormat(json: string, format: FileFormat): boolean {
let parsed: unknown;
try {
parsed = JSON.parse(json);
} catch {
return false;
}
if (format === FileFormat.CSV && !Array.isArray(parsed) && typeof parsed === "object" && parsed !== null) {
return true; // wrapped to [parsed] inside
}
return parsed !== undefined;
} Type guard
function isCsvConvertibleArray(value: unknown): value is Record<string, unknown>[] {
return Array.isArray(value) && value.every(v => v !== null && typeof v === "object" && !Array.isArray(v));
} Try / catch
} catch (error) {
console.error("jsonToContent failed", { format, len: json.length, error });
return json;
} Prevention
- Never log the entire json payload — log its length or a hash to keep the console usable and avoid leaking data.
- For CSV, flatten or reject arrays with incompatible element shapes before calling json2csv.
- Pass a replacer/nullChecker to js-yaml and json-2-csv to handle non-serializable values.
When it happens
Trigger: Exporting to CSV when the JSON contains deeply nested objects with mixed array/scalar shapes that expandArrayObjects cannot flatten; dumping a structure with undefined/Function values to YAML; JSON.parse(json) throwing because content was edited to be invalid between parse and convert.
Common situations: Mixed-schema array exported to CSV; YAML dump of an object with circular refs or BigInt; XML builder encountering non-string attribute values after partial edits; large payload flooding the console because the whole json is logged.
Related errors
- The content was unable to be converted, so it was cleared in
- error
- error
- JSON parsing failed for graph mode.
AI-assisted analysis of AykutSarac/jsoncrack.com@3c9af69e23 (2026-08-12).
Data as JSON: /api/errors/5790583e4b71fbec.
Report an issue: GitHub.