{
  "name": "CSV to JSON",
  "nodes": [
    {
      "id": "27f35089-7d23-425b-92b7-b5c45a79728d",
      "name": "Run manually",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -800,
        0
      ],
      "parameters": {}
    },
    {
      "id": "65ac01be-4a74-480e-9887-3b70797cf9ba",
      "name": "Read orders CSV",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1.1,
      "position": [
        -560,
        0
      ],
      "parameters": {
        "fileSelector": "/home/hatch/.n8n-files/orders.csv",
        "operation": "read",
        "options": {}
      }
    },
    {
      "id": "046b4e15-2e85-449f-8f01-b676c22a9aab",
      "name": "Parse CSV to JSON",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -320,
        0
      ],
      "parameters": {
        "jsCode": "// Read the CSV text the Read node loaded, then parse it into one JSON\n// item per row. Quoted fields may contain commas, escaped quotes (\"\"),\n// and line breaks, so a split on commas would break them.\n//\n// Binary data is stored on disk in filesystem mode, so the item only\n// carries the marker \"filesystem-v2\" in its data field. The bytes come\n// from this.helpers.getBinaryDataBuffer, which reads them from the store.\nconst buffer = await this.helpers.getBinaryDataBuffer(0, 'data');\nconst text = buffer.toString('utf8');\n\nfunction parseCsv(input) {\n  const rows = [];\n  let row = [];\n  let field = '';\n  let inQuotes = false;\n  for (let i = 0; i < input.length; i++) {\n    const ch = input[i];\n    if (inQuotes) {\n      if (ch === '\"') {\n        if (input[i + 1] === '\"') { field += '\"'; i++; }\n        else { inQuotes = false; }\n      } else { field += ch; }\n    } else if (ch === '\"') {\n      inQuotes = true;\n    } else if (ch === ',') {\n      row.push(field); field = '';\n    } else if (ch === '\\r') {\n      // Ignore carriage returns; the newline below ends the row.\n    } else if (ch === '\\n') {\n      row.push(field); field = '';\n      rows.push(row); row = [];\n    } else { field += ch; }\n  }\n  if (field !== '' || row.length > 0) { row.push(field); rows.push(row); }\n  return rows;\n}\n\nconst parsed = parseCsv(text);\nconst headers = parsed[0];\nconst rows = parsed.slice(1).filter((r) => r.some((v) => v !== ''));\nreturn rows.map((r) => {\n  const json = {};\n  headers.forEach((h, i) => { json[h] = r[i] ?? ''; });\n  return { json };\n});",
        "mode": "runOnceForAllItems"
      }
    },
    {
      "id": "0126d2c4-6b59-400d-8032-cc256af52dc6",
      "name": "To JSON file",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.2,
      "position": [
        -80,
        0
      ],
      "parameters": {
        "binaryPropertyName": "data",
        "mode": "once",
        "operation": "toJson",
        "options": {
          "encoding": "utf8",
          "fileName": "orders.json",
          "format": true
        }
      }
    },
    {
      "id": "ac2048e1-22fb-4822-b71d-3b45d8bc2131",
      "name": "Write orders JSON",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1.1,
      "position": [
        160,
        0
      ],
      "parameters": {
        "dataPropertyName": "data",
        "fileName": "/home/hatch/.n8n-files/orders.json",
        "operation": "write",
        "options": {}
      }
    }
  ],
  "connections": {
    "Parse CSV to JSON": {
      "main": [
        [
          {
            "index": 0,
            "node": "To JSON file",
            "type": "main"
          }
        ]
      ]
    },
    "Read orders CSV": {
      "main": [
        [
          {
            "index": 0,
            "node": "Parse CSV to JSON",
            "type": "main"
          }
        ]
      ]
    },
    "Run manually": {
      "main": [
        [
          {
            "index": 0,
            "node": "Read orders CSV",
            "type": "main"
          }
        ]
      ]
    },
    "To JSON file": {
      "main": [
        [
          {
            "index": 0,
            "node": "Write orders JSON",
            "type": "main"
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}