From 4401ab1974949f553881648c42411819b2a1e0c9 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Feb 2026 10:37:15 +0000 Subject: [PATCH] Fix seed script to parse NDJSON format data file The data file (id_county_item.json) contains newline-delimited JSON (one JSON object per line), but the seed script was calling JSON.parse() on the entire file contents, which fails because it's not valid JSON as a whole. Split by newlines and parse each line individually. https://claude.ai/code/session_01MGJ4Yh1BQm4i3ofBFfyWMq --- scripts/seed.js | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/scripts/seed.js b/scripts/seed.js index fd2e273..7676077 100644 --- a/scripts/seed.js +++ b/scripts/seed.js @@ -99,23 +99,13 @@ async function seed() { } } - // Read and parse JSON data + // Read and parse NDJSON data (one JSON object per line) console.log('📖 Reading data file...'); const rawData = fs.readFileSync(DATA_FILE, 'utf8'); - const data = JSON.parse(rawData); - - // Convert object to array of documents - const documents = []; - for (const [areaName, items] of Object.entries(data)) { - if (Array.isArray(items)) { - for (const item of items) { - documents.push({ - Areaname: areaName, - ...item - }); - } - } - } + const documents = rawData + .split('\n') + .filter(line => line.trim()) + .map(line => JSON.parse(line)); if (documents.length === 0) { console.error('❌ No documents found in data file');