Skip to content

yj -jt truncates JSON object keys containing commas when converting to TOML #52

Description

@drupol

yj truncates JSON object keys containing commas when converting to TOML

When converting JSON to TOML with yj -jt, object keys containing a comma are emitted incorrectly.

For example, the JSON string:

{"stack(x,n)":"foobar"}

is converted to:

"stack(x" = "foobar"

instead of preserving the full key.

This appears to truncate the key at the comma, which produces invalid / incorrect TOML output.

Reproduce the issue with:

echo '{"stack(x,n)":"foobar"}' | yj -jt

Observed output:

"stack(x" = "foobar"

The full key should be preserved in the generated TOML, for example something like:

"stack(x,n)" = "foobar"

I first hit this through Nix, where TOML generation recently switched to yj in NixOS/nixpkgs (NixOS/nixpkgs#510585). The following repro in the Nix REPL shows the same problem:

builtins.readFile ((pkgs.formats.toml {}).generate "jj" { "stack(x,n)" = "foobar"; })

which produces:

"\"stack(x\" = \"foobar\"\n"

For comparison, another JSON→TOML converter (https://github.com/pelletier/go-toml) preserves the key correctly:

echo '{"stack(x,n)":"foobar"}' | jsontoml

Output:

'stack(x,n)' = 'foobar'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions