fitnr/SublimeDataConverter

CSV to JSON returns empty []

Closed this issue · 4 comments

Hey!

Thanks a lot for the converter.

This is the CSV I'm trying to convert:
aardvark <div style="margin-left:1em"><i class="p" style="color:green">noun</i></div><div style="margin-left:1em"><span style="color:darkslateblue">BrE</span> <span style="color:gray">/</span><span style="color:navy">ˈɑːdvɑːk</span><span style="color:gray">/</span> ; <span style="color:indianred">NAmE</span> <span style="color:gray">/</span><span style="color:navy">ˈɑːrdvɑːrk</span><span style="color:gray">/</span> </div><div style="margin-left:1em"><br/></div><div style="margin-left:1em">an animal from southern Africa that has a long nose and tongue and that eats insects</div><div style="margin-left:1em"><br/></div><div style="margin-left:1em"><span style="color:cadetblue">→ see related entries:</span> <a href="Wild mammals">Wild mammals</a></div><div style="margin-left:1em"><br/></div><div style="margin-left:1em"><span style="color:mediumblue"><b>Word Origin</b></span></div><div style="margin-left:1em">late 18th cent.: from South African Dutch, from <i>aarde</i> ‘earth’ + <i>vark</i> ‘pig’.</div><div style="margin-left:1em"><br/></div>

This is my user settings:

{
	  "delimiter": "\t",
	  "headers": "never"
}

Also tried "headers" with "sniff" and "false".
Sublime version 3.2.1, python 3.7, Mac OS 10.14.5

Result:
I open package command palette and search for datacoverter, select the option to JSON (array of rows) and it transforms into this:
[]

Incidentally, it works fine when I use this service https://www.csvjson.com/csv2json and check the checkmark "Transpose". If I don't check it, it doesn't work.

I'll appreciate if you can take a look on this.

fitnr commented

The problem is that the header setting wasn't been properly read, I just pushed a commit that should fix that.
The "delimiter" setting is only used when the plugin can't sniff a delimiter. To force a particular flavor of delimited text, use the "dialect" and "use_dialect" settings. This worked for me:

{
  "dialects": {
    "aardvark": {
      "delimiter": "\t",
      "quotechar": "\\"
    },
  "use_dialect": "aardvark"
}

Thanks for the quick turnover! I pulled the changes into my sublime.

Here are my settings:

{
	"headers": "false",
  	"dialects": { 
    	"aardvark": {
     		"delimiter": "\t",
    		"quotechar": "\\"
    	},
  	"use_dialect": "aardvark"
	}
}

Here is the file I'm trying on:
reference_csv.txt

Here is the result I'm getting:

[
 [
  "learned\t<div style=\"margin-left:1em; color: rgb(240",
  "240",
  "241);font-size:16pt; font-family:SFProText-Regular\"><i class=\"p\" style=\"color:rgb(73",
  "206",
  "206);font-size:18pt;font-family:SFProDisplay-Italic\">adjective</i></div><div style=\"margin-left:1em; color: rgb(240",
  "240",
  "241);font-size:16pt; font-family:SFProText-Regular\"><span style=\"color:rgb(243",
  "115",
  "115);font-size:14pt; font-family: SFProDisplay-Semibold\">UK</span> <span style=\"color:gray\">/</span><span style=\"color:rgb(254",
  "255",
  "255); font-size:14pt; font-family: SFProDisplay-Light\">\u02c8l\u025c\u02d0n\u026ad</span><span style=\"color:gray\">/</span> \u00a0 <span style=\"color:rgb(243",
  "115",
  "115);font-size:14pt; font-family: SFProDisplay-Semibold\">USA</span> <span style=\"color:gray\">/</span><span style=\"color:rgb(254",
  "255",
  "255); font-size:14pt; font-family: SFProDisplay-Light\">\u02c8l\u025c\u02d0rn\u026ad</span><span style=\"color:gray\">/</span> </div><div style=\"margin-left:1em; color: rgb(240",
  "240",
....
...
...
...

It looks like a delimiter issue again.

Another example.
I have 3 lines here:
example2.txt

The result JSON is actually 2 arrays instead of 3.

example2-json.txt

Although is this a separate issue?

P.S. I'm uploading .txt bc GitHub doesn't allow other text formats.

hey, please let me know if you can find some time to check on this issue any time soon.