MCPcopy Index your code
hub / github.com/simstudioai/sim / sanitizeJsonHeaders

Function sanitizeJsonHeaders

apps/sim/lib/table/import.ts:434–461  ·  view source on GitHub ↗
(
  headers: string[],
  rows: Record<string, unknown>[]
)

Source from the content-addressed store, hash-verified

432 * underscore. Returns the headers and rows untouched when no key needs renaming.
433 */
434export function sanitizeJsonHeaders(
435 headers: string[],
436 rows: Record<string, unknown>[]
437): { headers: string[]; rows: Record<string, unknown>[] } {
438 const renamed = new Map<string, string>()
439 const seen = new Set<string>()
440
441 for (const raw of headers) {
442 let safe = sanitizeName(raw)
443 while (seen.has(safe)) safe = `${safe}_`
444 seen.add(safe)
445 renamed.set(raw, safe)
446 }
447
448 const noChange = headers.every((h) => renamed.get(h) === h)
449 if (noChange) return { headers, rows }
450
451 return {
452 headers: headers.map((h) => renamed.get(h)!),
453 rows: rows.map((row) => {
454 const out: Record<string, unknown> = {}
455 for (const [raw, safe] of renamed) {
456 if (raw in row) out[safe] = row[raw]
457 }
458 return out
459 }),
460 }
461}
462
463/**
464 * Parses a JSON payload that must be an array of plain objects into the same

Callers 1

parseJsonRowsFunction · 0.85

Calls 4

sanitizeNameFunction · 0.70
setMethod · 0.65
getMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected