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

CSV conversion to JSON splits string on : to become a subfield. #1947

Closed
chrisguest75 opened this issue Feb 14, 2024 · 2 comments
Closed

CSV conversion to JSON splits string on : to become a subfield. #1947

chrisguest75 opened this issue Feb 14, 2024 · 2 comments
Labels

Comments

@chrisguest75
Copy link

When transforming CSV strings to JSON objects. Strings that contains : will be split into a field.
With the field name being the LHS of the : and the value being the RHS.

Version of yq: 4.40.4
Operating system: WSL using linxbrew
Installed via: homebrew

Input CSV

id,mystring
1,hello world
2,hello: world

Command
The command you ran:

yq -o=json ./csv/bug2.csv 

Actual behavior

[
  {
    "id": 1,
    "mystring": "hello world"
  },
  {
    "id": 2,
    "mystring": {
      "hello": "world"
    }
  }
]

Expected behavior

[
  {
    "id": 1,
    "mystring": "hello world"
  },
  {
    "id": 2,
    "mystring":"hello: world"
    }
  }
]

Additional context

It also fails when using quoted strings.

"id","mystring"
"1","hello world"
"2","hello: world"
@mikefarah
Copy link
Owner

That's a good point, I'll add a new flag in the next release to turn off auto-parsing. It'll be on by default for backwards compatibility.

@mikefarah
Copy link
Owner

Fixed in 4.41.1, you'll need to pass in the new flag --csv-auto-parse=f, as shown here: https://mikefarah.gitbook.io/yq/usage/csv-tsv#parse-csv-into-an-array-of-objects-no-auto-parsing

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

No branches or pull requests

2 participants