Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csv2json issues #291

Open
datatraveller1 opened this issue Oct 30, 2024 · 3 comments
Open

csv2json issues #291

datatraveller1 opened this issue Oct 30, 2024 · 3 comments

Comments

@datatraveller1
Copy link

Prerequisites

version: csvtk v0.30.0

Describe your issue

I have noticed four issues with the csv2json command.

command: csvtk csv2json testdata.csv -o testdata.json

input file testdata.csv:
test
none
"Make America ""great"" again"
\nations
"This is a
MULTILINE
string"

actual output file testdata.json:

[
  {
    "test": null
  },
  {
    "test": "Make America "great" again"
  },
  {
    "test": "\nations"
  },
  {
    "test": "This is a
MULTILINE
string"
  }
]

expected output file testdata.json:

[
  {
    "test": "none"
  },
  {
    "test": "Make America \"great\" again"
  },
  {
    "test": "\\nations"
  },
  {
    "test": "This is a\nMULTILINE\nstring"
  }
]

Comments:

  • issue 1: I want "none" to be depicted literally and neither changed to "null" (no option) nor "" (empty string with option -b)

  • issue 2: In JSON, double quotes have to be escaped with a backslash (\")

  • issue 3: In JSON, backslashes have to be escaped with a backslash (\\)

  • issue 4: In JSON, the line breaks of a CSV multiline cell have to be depicted as \n

Thank you

Thank you very much for the great csvtk tool!

@shenwei356
Copy link
Owner

OK, fixed, and it will be available in the next release.

$ go build && cat testdata.csv | ./csvtk csv2json -b
[
  {
    "test": "none"
  },
  {
    "test": "Make America \"great\" again"
  },
  {
    "test": "\\nations"
  },
  {
    "test": "This is a\nMULTILINE\nstring"
  }
]

@datatraveller1
Copy link
Author

datatraveller1 commented Nov 2, 2024

Great thank you, very much! I can confirm it works fine on MS Windows with version 0.31.0.
LF and CRLF get changed to "\n" which is the best solution both for Linux and Windows.

A small note for the next version, although this is very rare in practice:
A tab character inside the CSV should be changed to "\t" in JSON.
Thank you again.

@shenwei356
Copy link
Owner

Thanks, I'll add these later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants