Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions docs/content/manual/dev/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2151,9 +2151,15 @@ sections:

* `@csv`:

The input must be an array, and it is rendered as CSV
with double quotes for strings, and quotes escaped by
repetition.
The input must be an array, and it is rendered as comma
separated CSV with double quotes for strings, and quotes
escaped by repetition.

* `@scsv`:

The input must be an array, and it is rendered as semicolon
separated CSV with double quotes for strings, and quotes
escaped by repetition.

* `@tsv`:

Expand Down
8 changes: 7 additions & 1 deletion jq.1.prebuilt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,19 @@ static jv f_format(jq_state *jq, jv input, jv fmt) {
} else if (!strcmp(fmt_s, "text")) {
jv_free(fmt);
return f_tostring(jq, input);
} else if (!strcmp(fmt_s, "csv") || !strcmp(fmt_s, "tsv")) {
} else if (!strcmp(fmt_s, "csv") || !strcmp(fmt_s, "scsv") || !strcmp(fmt_s, "tsv")) {
const char *quotes, *sep, *escapings;
const char *msg;
if (!strcmp(fmt_s, "csv")) {
msg = "cannot be csv-formatted, only array";
quotes = "\"";
sep = ",";
escapings = "\"\"\"\0";
} else if (!strcmp(fmt_s, "scsv")) {
msg = "cannot be scsv-formatted, only array";
quotes = "\"";
sep = ";";
escapings = "\"\"\"\0";
} else {
msg = "cannot be tsv-formatted, only array";
assert(!strcmp(fmt_s, "tsv"));
Expand Down
3 changes: 2 additions & 1 deletion tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ null
null
"interpolation"

@text,@json,([1,.]|@csv,@tsv),@html,(@uri|.,@urid),@sh,(@base64|.,@base64d)
@text,@json,([1,.]|@csv,@scsv,@tsv),@html,(@uri|.,@urid),@sh,(@base64|.,@base64d)
"!()<>&'\"\t"
"!()<>&'\"\t"
"\"!()<>&'\\\"\\t\""
"1,\"!()<>&'\"\"\t\""
"1;\"!()<>&'\"\"\t\""
"1\t!()<>&'\"\\t"
"!()&lt;&gt;&amp;&apos;&quot;\t"
"%21%28%29%3C%3E%26%27%22%09"
Expand Down
Loading