Skip to content

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

Closed
@chrisguest75

Description

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"

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions