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

JSONL output does not properly handle keys with quotes #1424

Closed
kusalananda opened this issue Nov 11, 2023 · 1 comment · Fixed by #1425
Closed

JSONL output does not properly handle keys with quotes #1424

kusalananda opened this issue Nov 11, 2023 · 1 comment · Fixed by #1425
Assignees
Labels

Comments

@kusalananda
Copy link

kusalananda commented Nov 11, 2023

I wanted to convert header-less CSV input into a single JSON object by using the 1st field as the key name and the 2nd field as the value for the corresponding field.

Using JSON output, I get the correct output, but in an array:

$ echo '"key with ""quote""","value with ""quote"""' | mlr --c2j -N put '$[$1]=$2' then cut -x -f 1,2
[
{
  "key with \"quote\"": "value with \"quote\""
}
]

Switching to JSONL output seems to break the quoting of the key, but handles the value correctly:

$ echo '"key with ""quote""","value with ""quote"""' | mlr --c2l -N put '$[$1]=$2' then cut -x -f 1,2
{"key with "quote"": "value with \"quote\""}

I'm using mlr version 6.9.0 for openbsd/amd64/go1.21.1.

@johnkerl johnkerl self-assigned this Nov 11, 2023
@johnkerl johnkerl added the bug label Nov 11, 2023
johnkerl added a commit that referenced this issue Nov 11, 2023
johnkerl added a commit that referenced this issue Nov 11, 2023
* mlr --l2j, --j2l

* make dev for previous commit

* fix #1424

* unit-test cases

* iterate
@johnkerl
Copy link
Owner

@kusalananda thank you for the bug report! :)

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

Successfully merging a pull request may close this issue.

2 participants