How to fix csv to json converter module?How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How can I convert a string to boolean in JavaScript?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How to check whether a string contains a substring in JavaScript?Why does Google prepend while(1); to their JSON responses?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?

Should the average user with no special access rights be worried about SMS-based 2FA being theoretically interceptable?

Late 1970's and 6502 chip facilities for operating systems

Performance for simple code that converts a RGB tuple to hex string

Which place in our solar system is mostly fit for terraforming?

Is the mass of paint relevant in rocket design?

Is there any iPhone SE out there with 3D Touch?

Did Apollo carry and use WD40?

Can a broken/split chain be reassembled?

My Project Manager does not accept carry-over in Scrum, Is that normal?

Why weren't the Death Star plans transmitted electronically?

Examples of "unsuccessful" theories with afterlives

Going to France with limited French for a day

Can the U.S. president make military decisions without consulting anyone?

I reverse the source code, you negate the input!

1, 2, 4, 8, 16, ... 33?

SOQL Join Opportunity, OpportunityLineItem, and Custom Object

What exactly did this mechanic sabotage on the American Airlines 737, and how dangerous was it?

Safely hang a mirror that does not have hooks

Worms crawling under skin

A simple game that keeps track of the number of questions asked

Would Taiwan and China's dispute be solved if Taiwan gave up being the Republic of China?

Are black holes bound to merge once their event horizons touch?

What can a pilot do if an air traffic controller is incapacitated?

Where are they calling from?



How to fix csv to json converter module?


How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How can I convert a string to boolean in JavaScript?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How to check whether a string contains a substring in JavaScript?Why does Google prepend while(1); to their JSON responses?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I can't figure out how to match the title and genre correctly based on what I have in my module.



The csv_json module has an exception where it doesn't match each of the properties accordingly and that is when the title has "The" in it.



//csv file



movieId,title,genre



1,"American President, The (1995)",Comedy|Drama|Romance
2,"Creation, The creator(xxxx)",Comedy|Drama|Romance
3,"Destruction, The destroyer(xxxxx)",Comedy|Drama|Romance




//csv_json module
const readline = require('readline');
const fs = require('fs');

function readCsv(pathToFile)
return new Promise((resolve, reject) =>
const csvReader = readline.createInterface(
input: fs.createReadStream(pathToFile)
);

let headers;
const rows = [];
let tempRows = [];
csvReader
.on('line', row =>
if (!headers)
headers = row.split(','); // header name breed age
else
rows.push(row.split(','));

)
.on('close', () =>
// then iterate through all of the "rows", matching them to the "headers"
for (var i = 0; i < rows.length; i++)
var obj = ;
var currentline = rows[i];

for (var j = 0; j < headers.length; j++)
obj[headers[j]] = currentline[j]; //Kitty Siamese 14


tempRows.push(obj);


resolve(JSON.stringify(tempRows));
);

// This would be in place of the "return" statement you had before
);


module.exports = readCsv;


//js file
const readCsv = require('./csvjson.js');

readCsv('movieTest.csv').then((data) =>
console.log(data)
let movieJson = JSON.parse(data);
console.log(movieJson)


/*data output:
["movieId":"1","title":""American President","genre":" The (1995)"","movieId":"2","title":""Creation","genre":" The creator(xxxx)"","movieId":"3","title":""Destruction","genre":" The destroyer(xxxxx)""]

*/
/*movieJson output:
[ movieId: '1',
title: '"American President',
genre: ' The (1995)"' ,
movieId: '2',
title: '"Creation',
genre: ' The creator(xxxx)"' ,
movieId: '3',
title: '"Destruction',
genre: ' The destroyer(xxxxx)"' ]
*/
);


I expect the output to match:



[ movieId: '1',
title: "American President, The (1995)",
genre:'Comedy,
movieId: '2',
title: "The creator(xxxx) Creation",
genre: ' Comedy,
movieId: '3',
title: "Destruction The destroyer(xxx)",
genre: ' Comedy ]









share|improve this question






























    1















    I can't figure out how to match the title and genre correctly based on what I have in my module.



    The csv_json module has an exception where it doesn't match each of the properties accordingly and that is when the title has "The" in it.



    //csv file



    movieId,title,genre



    1,"American President, The (1995)",Comedy|Drama|Romance
    2,"Creation, The creator(xxxx)",Comedy|Drama|Romance
    3,"Destruction, The destroyer(xxxxx)",Comedy|Drama|Romance




    //csv_json module
    const readline = require('readline');
    const fs = require('fs');

    function readCsv(pathToFile)
    return new Promise((resolve, reject) =>
    const csvReader = readline.createInterface(
    input: fs.createReadStream(pathToFile)
    );

    let headers;
    const rows = [];
    let tempRows = [];
    csvReader
    .on('line', row =>
    if (!headers)
    headers = row.split(','); // header name breed age
    else
    rows.push(row.split(','));

    )
    .on('close', () =>
    // then iterate through all of the "rows", matching them to the "headers"
    for (var i = 0; i < rows.length; i++)
    var obj = ;
    var currentline = rows[i];

    for (var j = 0; j < headers.length; j++)
    obj[headers[j]] = currentline[j]; //Kitty Siamese 14


    tempRows.push(obj);


    resolve(JSON.stringify(tempRows));
    );

    // This would be in place of the "return" statement you had before
    );


    module.exports = readCsv;


    //js file
    const readCsv = require('./csvjson.js');

    readCsv('movieTest.csv').then((data) =>
    console.log(data)
    let movieJson = JSON.parse(data);
    console.log(movieJson)


    /*data output:
    ["movieId":"1","title":""American President","genre":" The (1995)"","movieId":"2","title":""Creation","genre":" The creator(xxxx)"","movieId":"3","title":""Destruction","genre":" The destroyer(xxxxx)""]

    */
    /*movieJson output:
    [ movieId: '1',
    title: '"American President',
    genre: ' The (1995)"' ,
    movieId: '2',
    title: '"Creation',
    genre: ' The creator(xxxx)"' ,
    movieId: '3',
    title: '"Destruction',
    genre: ' The destroyer(xxxxx)"' ]
    */
    );


    I expect the output to match:



    [ movieId: '1',
    title: "American President, The (1995)",
    genre:'Comedy,
    movieId: '2',
    title: "The creator(xxxx) Creation",
    genre: ' Comedy,
    movieId: '3',
    title: "Destruction The destroyer(xxx)",
    genre: ' Comedy ]









    share|improve this question


























      1












      1








      1








      I can't figure out how to match the title and genre correctly based on what I have in my module.



      The csv_json module has an exception where it doesn't match each of the properties accordingly and that is when the title has "The" in it.



      //csv file



      movieId,title,genre



      1,"American President, The (1995)",Comedy|Drama|Romance
      2,"Creation, The creator(xxxx)",Comedy|Drama|Romance
      3,"Destruction, The destroyer(xxxxx)",Comedy|Drama|Romance




      //csv_json module
      const readline = require('readline');
      const fs = require('fs');

      function readCsv(pathToFile)
      return new Promise((resolve, reject) =>
      const csvReader = readline.createInterface(
      input: fs.createReadStream(pathToFile)
      );

      let headers;
      const rows = [];
      let tempRows = [];
      csvReader
      .on('line', row =>
      if (!headers)
      headers = row.split(','); // header name breed age
      else
      rows.push(row.split(','));

      )
      .on('close', () =>
      // then iterate through all of the "rows", matching them to the "headers"
      for (var i = 0; i < rows.length; i++)
      var obj = ;
      var currentline = rows[i];

      for (var j = 0; j < headers.length; j++)
      obj[headers[j]] = currentline[j]; //Kitty Siamese 14


      tempRows.push(obj);


      resolve(JSON.stringify(tempRows));
      );

      // This would be in place of the "return" statement you had before
      );


      module.exports = readCsv;


      //js file
      const readCsv = require('./csvjson.js');

      readCsv('movieTest.csv').then((data) =>
      console.log(data)
      let movieJson = JSON.parse(data);
      console.log(movieJson)


      /*data output:
      ["movieId":"1","title":""American President","genre":" The (1995)"","movieId":"2","title":""Creation","genre":" The creator(xxxx)"","movieId":"3","title":""Destruction","genre":" The destroyer(xxxxx)""]

      */
      /*movieJson output:
      [ movieId: '1',
      title: '"American President',
      genre: ' The (1995)"' ,
      movieId: '2',
      title: '"Creation',
      genre: ' The creator(xxxx)"' ,
      movieId: '3',
      title: '"Destruction',
      genre: ' The destroyer(xxxxx)"' ]
      */
      );


      I expect the output to match:



      [ movieId: '1',
      title: "American President, The (1995)",
      genre:'Comedy,
      movieId: '2',
      title: "The creator(xxxx) Creation",
      genre: ' Comedy,
      movieId: '3',
      title: "Destruction The destroyer(xxx)",
      genre: ' Comedy ]









      share|improve this question














      I can't figure out how to match the title and genre correctly based on what I have in my module.



      The csv_json module has an exception where it doesn't match each of the properties accordingly and that is when the title has "The" in it.



      //csv file



      movieId,title,genre



      1,"American President, The (1995)",Comedy|Drama|Romance
      2,"Creation, The creator(xxxx)",Comedy|Drama|Romance
      3,"Destruction, The destroyer(xxxxx)",Comedy|Drama|Romance




      //csv_json module
      const readline = require('readline');
      const fs = require('fs');

      function readCsv(pathToFile)
      return new Promise((resolve, reject) =>
      const csvReader = readline.createInterface(
      input: fs.createReadStream(pathToFile)
      );

      let headers;
      const rows = [];
      let tempRows = [];
      csvReader
      .on('line', row =>
      if (!headers)
      headers = row.split(','); // header name breed age
      else
      rows.push(row.split(','));

      )
      .on('close', () =>
      // then iterate through all of the "rows", matching them to the "headers"
      for (var i = 0; i < rows.length; i++)
      var obj = ;
      var currentline = rows[i];

      for (var j = 0; j < headers.length; j++)
      obj[headers[j]] = currentline[j]; //Kitty Siamese 14


      tempRows.push(obj);


      resolve(JSON.stringify(tempRows));
      );

      // This would be in place of the "return" statement you had before
      );


      module.exports = readCsv;


      //js file
      const readCsv = require('./csvjson.js');

      readCsv('movieTest.csv').then((data) =>
      console.log(data)
      let movieJson = JSON.parse(data);
      console.log(movieJson)


      /*data output:
      ["movieId":"1","title":""American President","genre":" The (1995)"","movieId":"2","title":""Creation","genre":" The creator(xxxx)"","movieId":"3","title":""Destruction","genre":" The destroyer(xxxxx)""]

      */
      /*movieJson output:
      [ movieId: '1',
      title: '"American President',
      genre: ' The (1995)"' ,
      movieId: '2',
      title: '"Creation',
      genre: ' The creator(xxxx)"' ,
      movieId: '3',
      title: '"Destruction',
      genre: ' The destroyer(xxxxx)"' ]
      */
      );


      I expect the output to match:



      [ movieId: '1',
      title: "American President, The (1995)",
      genre:'Comedy,
      movieId: '2',
      title: "The creator(xxxx) Creation",
      genre: ' Comedy,
      movieId: '3',
      title: "Destruction The destroyer(xxx)",
      genre: ' Comedy ]






      javascript node.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 16:39









      Gracias Peterson ClaudeGracias Peterson Claude

      317 bronze badges




      317 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1
















          This is probably since you're splitting each row on every occurrence of a comma.



          const row = '1,"American President, The (1995)",Comedy|Drama|Romance'
          row.split(',')
          // returns ["1", ""American President", " The (1995)"", "Comedy|Drama|Romance"]


          Try replacing every comma that is not followed by a whitespace with some unique string that wouldn't occur anywhere else in the CSV file, and then split on that:



          row.replace(/,(S)/g, '&unique;$1').split('&unique;')
          // returns ["1", ""American President, The (1995)"", "Comedy|Drama|Romance"]


          Hope this helps! :)






          share|improve this answer

























          • Yes that worked thank you so much.

            – Gracias Peterson Claude
            Mar 28 at 17:19













          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55402809%2fhow-to-fix-csv-to-json-converter-module%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1
















          This is probably since you're splitting each row on every occurrence of a comma.



          const row = '1,"American President, The (1995)",Comedy|Drama|Romance'
          row.split(',')
          // returns ["1", ""American President", " The (1995)"", "Comedy|Drama|Romance"]


          Try replacing every comma that is not followed by a whitespace with some unique string that wouldn't occur anywhere else in the CSV file, and then split on that:



          row.replace(/,(S)/g, '&unique;$1').split('&unique;')
          // returns ["1", ""American President, The (1995)"", "Comedy|Drama|Romance"]


          Hope this helps! :)






          share|improve this answer

























          • Yes that worked thank you so much.

            – Gracias Peterson Claude
            Mar 28 at 17:19















          1
















          This is probably since you're splitting each row on every occurrence of a comma.



          const row = '1,"American President, The (1995)",Comedy|Drama|Romance'
          row.split(',')
          // returns ["1", ""American President", " The (1995)"", "Comedy|Drama|Romance"]


          Try replacing every comma that is not followed by a whitespace with some unique string that wouldn't occur anywhere else in the CSV file, and then split on that:



          row.replace(/,(S)/g, '&unique;$1').split('&unique;')
          // returns ["1", ""American President, The (1995)"", "Comedy|Drama|Romance"]


          Hope this helps! :)






          share|improve this answer

























          • Yes that worked thank you so much.

            – Gracias Peterson Claude
            Mar 28 at 17:19













          1














          1










          1









          This is probably since you're splitting each row on every occurrence of a comma.



          const row = '1,"American President, The (1995)",Comedy|Drama|Romance'
          row.split(',')
          // returns ["1", ""American President", " The (1995)"", "Comedy|Drama|Romance"]


          Try replacing every comma that is not followed by a whitespace with some unique string that wouldn't occur anywhere else in the CSV file, and then split on that:



          row.replace(/,(S)/g, '&unique;$1').split('&unique;')
          // returns ["1", ""American President, The (1995)"", "Comedy|Drama|Romance"]


          Hope this helps! :)






          share|improve this answer













          This is probably since you're splitting each row on every occurrence of a comma.



          const row = '1,"American President, The (1995)",Comedy|Drama|Romance'
          row.split(',')
          // returns ["1", ""American President", " The (1995)"", "Comedy|Drama|Romance"]


          Try replacing every comma that is not followed by a whitespace with some unique string that wouldn't occur anywhere else in the CSV file, and then split on that:



          row.replace(/,(S)/g, '&unique;$1').split('&unique;')
          // returns ["1", ""American President, The (1995)"", "Comedy|Drama|Romance"]


          Hope this helps! :)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 28 at 16:55









          Nils LockeanNils Lockean

          1095 bronze badges




          1095 bronze badges















          • Yes that worked thank you so much.

            – Gracias Peterson Claude
            Mar 28 at 17:19

















          • Yes that worked thank you so much.

            – Gracias Peterson Claude
            Mar 28 at 17:19
















          Yes that worked thank you so much.

          – Gracias Peterson Claude
          Mar 28 at 17:19





          Yes that worked thank you so much.

          – Gracias Peterson Claude
          Mar 28 at 17:19




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55402809%2fhow-to-fix-csv-to-json-converter-module%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현