简体   繁体   English

如何验证 node.js 中的 csv 文件?

[英]How to validate a csv file in node.js?

I have a large csv file that I need to convert to json, and then store the data into neo4j.我有一个很大的 csv 文件,我需要将其转换为 json,然后将数据存储到 neo4j 中。 I am using the csv-parser plugin for node.js.我正在为 node.js 使用 csv-parser 插件。 This works fine if the csv is valid.如果 csv 有效,这可以正常工作。 However if it's not valid, then the data in neo4j gets scrambled.但是,如果它无效,那么neo4j 中的数据就会被打乱。 Therefore I need to validate the file, before I can send it into my database.因此,我需要验证文件,然后才能将其发送到我的数据库中。 Are there any existing plugins available or is there a way for me to validate the csv file myself?是否有任何现有的插件可用,或者有没有办法让我自己验证 csv 文件?

You might look into checking out the API for csvlint您可能会考虑查看csvlint的 API

I also suggest checking out this similar answer .我还建议查看这个类似的答案 (Below this answer also has good csvlint info, too) (在这个答案下面也有很好的 csvlint 信息)

There is also fast-csv which has some validation built in, which may help depending on your needs.还有fast-csv内置了一些验证,这可能会根据您的需要提供帮助。

Otherwise, finding a validator that caters to your specific needs may be difficult, and I suggest writing editing your node script to validate it for yourself.否则,找到满足您特定需求的验证器可能会很困难,我建议您编写编辑节点脚本来自己验证它。


Update: I would also like to recommend Papa Parse , which has several parsing options.更新:我还想推荐Papa Parse ,它有几个解析选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM