{"record":{"id":"5790583e4b71fbec","repo":"AykutSarac/jsoncrack.com","slug":"json-error","errorCode":null,"errorMessage":"json, error","messagePattern":"json, error","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/www/src/lib/utils/jsonAdapter.ts","lineNumber":90,"sourceCode":"\n    if (format === FileFormat.CSV) {\n      const { json2csv } = await import(\"json-2-csv\");\n      const parsedJson = JSON.parse(json);\n\n      const data = Array.isArray(parsedJson) ? parsedJson : [parsedJson];\n      return json2csv(data, {\n        expandArrayObjects: true,\n        expandNestedObjects: true,\n        excelBOM: true,\n        wrapBooleans: true,\n        trimFieldValues: true,\n        trimHeaderFields: true,\n      });\n    }\n\n    return json;\n  } catch (error) {\n    console.error(json, error);\n    return json;\n  }\n};\n","sourceCodeStart":72,"sourceCodeEnd":94,"githubUrl":"https://github.com/AykutSarac/jsoncrack.com/blob/3c9af69e23c635356293b6b28cf4cd0af10d1059/apps/www/src/lib/utils/jsonAdapter.ts#L72-L94","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n} catch (error) {\n  console.error(json, error);\n  return json;\n}\n\n// after\n} catch (error) {\n  console.error(\"jsonToContent failed for format\", format, \"len\", json.length, error);\n  return json;\n}","handlingStrategy":"validation","validationCode":"// Validate before converting\nfunction isSerializableForFormat(json: string, format: FileFormat): boolean {\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(json);\n  } catch {\n    return false;\n  }\n  if (format === FileFormat.CSV && !Array.isArray(parsed) && typeof parsed === \"object\" && parsed !== null) {\n    return true; // wrapped to [parsed] inside\n  }\n  return parsed !== undefined;\n}","typeGuard":"function isCsvConvertibleArray(value: unknown): value is Record<string, unknown>[] {\n  return Array.isArray(value) && value.every(v => v !== null && typeof v === \"object\" && !Array.isArray(v));\n}","tryCatchPattern":"} catch (error) {\n  console.error(\"jsonToContent failed\", { format, len: json.length, error });\n  return json;\n}","preventionTips":["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."],"tags":["serialization","csv","yaml","xml","json-parse"],"backgroundTag":null,"analyzedSha":"3c9af69e23c635356293b6b28cf4cd0af10d1059","analyzedAt":"2026-08-12T19:00:27.891Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}