How to import json/array from csv?

No matter what I try I can't import json/array properly from a csv file.
This is how it looks in file

[{"cost":0,"name":"Home inspection","in_loan":0,"percent":0,"cost_type":"set-amount"},{"cost":0,"name":"Appraisal","in_loan":0,"percent":0,"cost_type":"set-amount"},{"cost":0,"name":"Loan Points","in_loan":0,"percent":0,"cost_type":"set-amount"},{"cost":0,"name":"Lender Fees","in_loan":0,"percent":0,"cost_type":"set-amount"},{"cost":0,"name":"Title & Escrow Fees","in_loan":0,"percent":0,"cost_type":"set-amount"},{"cost":0,"name":"Transfer Taxes","in_loan":0,"percent":0,"cost_type":"set-amount"},{"cost":0,"name":"Attorney Fees","in_loan":0,"percent":0,"cost_type":"set-amount"},{"cost":0,"name":"Wholesaler Fees","in_loan":0,"percent":0,"cost_type":"set-amount"}]


This is in my importer class

ImportColumn::make('purchase_costs')
  ->castStateUsing(function (string $state): ?array {
      if (blank($state)) {
          return null;
      }

      return json_decode($state, true); // Decode JSON string to an associative array
  }),


This is how it looks in my DB

"[{\"cost\":0,\"name\":\"Home inspection\",\"in_loan\":0,\"percent\":0,\"cost_type\":\"set-amount\"},{\"cost\":0,\"name\":\"Appraisal\",\"in_loan\":0,\"percent\":0,\"cost_type\":\"set-amount\"},{\"cost\":0,\"name\":\"Loan Points\",\"in_loan\":0,\"percent\":0,\"cost_type\":\"set-amount\"},{\"cost\":0,\"name\":\"Lender Fees\",\"in_loan\":0,\"percent\":0,\"cost_type\":\"set-amount\"},{\"cost\":0,\"name\":\"Title & Escrow Fees\",\"in_loan\":0,\"percent\":0,\"cost_type\":\"set-amount\"},{\"cost\":0,\"name\":\"Transfer Taxes\",\"in_loan\":0,\"percent\":0,\"cost_type\":\"set-amount\"},{\"cost\":0,\"name\":\"Attorney Fees\",\"in_loan\":0,\"percent\":0,\"cost_type\":\"set-amount\"},{\"cost\":0,\"name\":\"Wholesaler Fees\",\"in_loan\":0,\"percent\":0,\"cost_type\":\"set-amount\"}]"
Was this page helpful?