mithrandie / csvq

SQL-like query language for csv
https://mithrandie.github.io/csvq
MIT License
1.51k stars 63 forks source link

How to set stdout to not escape content? #120

Open hw2499 opened 5 months ago

hw2499 commented 5 months ago

The JSON content includes BackSLASH The following code Stdout:=query NewOutput() Csvq SetStdout (stdout) Fmt Println ("stdout. String():", stdout String() It was found that the output of stdout escaped/opt/, resulting in \/opt \/, This is not the desired effect, what if it is set to incorrect/escaped?

mithrandie commented 5 months ago

Please provide more details on the following information.

  1. Codes for reproduction of the result, and its input data if necessary.
  2. The output result of executing that code.
  3. Desired output result.
hw2499 commented 5 months ago

Thank you for your reply .

1. file content

key;value MrLi; {path1:/usr/local/a} MrAa; {path1:/usr/local/b}

2. code:

queryString := "" + "SET @@IMPORT_FORMAT TO JSON;" + "SET @@FORMAT TO JSON;" + "SET @@PRETTY_PRINT TO TRUE;" + "SET @@DELIMITER TO ';';"

_, err = db.Exec(queryString)
if err != nil {
    fmt.Println("runtime fail:", err)

}

stdout := query.NewOutput()
csvq.SetStdout(stdout)
queryString = "select * from `readme2.csv`"
_, err = db.Query(queryString)
if err != nil {
    fmt.Println("query fail:", err)

}
fmt.Println("stdout.String():", stdout.String())

3. output result

stdout.String(): [
  {
    "key": "MrLi",
    "value": " {path1:\/usr\/local\/a}"
  },
  {
    "key": "MrAa",
    "value": " {path1:\/usr\/local\/b}"
  }
]

4. Desired output result.

[ { "key": "MrLi", "value": " {path1:/usr/local/a}" }, { "key": "MrAa", "value": " {path1:/usr/local/b}" } ]

mithrandie commented 4 months ago

Thank you, I understand what you want.

According to RFC8259, solidus (U+002F) is not MUST be escaped, but it is listed as a character to be escaped, so csvq is also escapes it in the output. It can be read with or without escaping when reading, but currently there is no option to exclude escaping of this character in the output.

hw2499 commented 4 months ago

Thank you for your reply. I hope to have time to implement this feature in the future