Skip to content

Conversion from TOML to JSON still omits empty tables #2459

@kiwi-oss

Description

@kiwi-oss

Describe the bug
#1924 was an issue where empty TOML tables haven't been converted to empty JSON objects. It has been supposedly fixed and closed, but it turns out that the fix isn't complete. It seems that empty tables are omitted from the output unless an empty table is the last table in the input. That's why it works for input containing only the empty table which is the only case for which a test has been added in the fix pull request.

Version of yq: 4.47.1
Operating system: Linux
Installed via: binary release

Input TOML
input.toml:

[firstEmptyTable]
[firstTableWithContent]
key = "value"
[secondEmptyTable]
[thirdEmptyTable]
[secondTableWithContent]
key = "value"
[fourthEmptyTable]
[fifthEmptyTable]

Command

yq --input-format toml --output-format json input.toml

Actual behavior

{
  "firstTableWithContent": {
    "key": "value"
  },
  "secondTableWithContent": {
    "key": "value"
  },
  "fifthEmptyTable": {}
}

Expected behavior

{
  "firstEmptyTable": {},
  "firstTableWithContent": {
    "key": "value"
  },
  "secondEmptyTable": {},
  "thirdEmptyTable": {},
  "secondTableWithContent": {
    "key": "value"
  },
  "fourthEmptyTable": {},
  "fifthEmptyTable": {}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions