janisdd / vscode-edit-csv

vs code extension to edit csv files with an excel like table ui
MIT License
229 stars 35 forks source link

Trailing quote error when json object stored in a string #100

Closed kennethpgreen closed 2 years ago

kennethpgreen commented 2 years ago

What OS?

Description

I see the following error when I try to open a csv using Edit CSV that has a string that is being used to store a json object. Ik this is funky to do something like this in the first place. Error: Trailing quote on quoted field is malformed on line 2.

Expected behavior

I would like to be able to see this string that holds json text in one cell in Edit CSV.

Steps to reproduce

Open the following file using Edit CSV in VSCode and observe the error above. test.csv

janisdd commented 2 years ago

At first glance I thought this was an error... but actually it isn't.

The file content was

id, json_data
1,"{\"key_1\":\"value\",\"key_2\":\"value\"}"

However, in csv quotes are escaped differently (with double quotes""), not with \" (by default). This can also be seen if you install the rainbow csv plugin.

So a correct version would be

id, json_data
1,"{\""key_1\"":\""value\"",\""key_2\"":\""value\""}"

If you insist on storing the quotes this way (probably to read them programatically), you can set the EscapeChar to \ in the Read (and Write options) and click on Reset data and apply read options to get your desired behavior.

Also, if you mostly deal with these files, you can set the default EscapeChar in the settings of the plugin: Read Option_escape Char and Write Option_escape Char

kennethpgreen commented 2 years ago

Thank you for the prompt and thorough response!