pelletier/go-toml

jsontoml - integers become floats

rleap-m opened this issue · 3 comments

Describe the bug
When using the jsontoml tool integers are converted to floats:

To Reproduce

$ cat fruit.toml
[fruit]
apples = 5
oranges = 3
bananas = 1
kiwis = 0

$ cat fruit.toml | tomljson
{
  "fruit": {
    "apples": 5,
    "bananas": 1,
    "kiwis": 0,
    "oranges": 3
  }
}

$ cat fruit.toml | tomljson | jsontoml
[fruit]
apples = 5.0
bananas = 1.0
kiwis = 0.0
oranges = 3.0

Expected behavior
When converting json to toml, integers should not be converted to floats.

Versions

  • go-toml: v2.0.5
  • go: go1.19.2 linux/amd64
  • operating system: e.g. Linux

This is a product using the encoding/json package to Unmarshal the input for jsontoml. json.Unmarshal decodes all JSON numbers as float64.

Duplicate of #780

@moorereason Sorry I missed the previously opened issue - thank you.

Just an FYI for others who might need an alternative CLI (yj - https://github.com/sclevine/yj) to do the conversion from JSON to TOML w/out the integer to float conversion issue:

$ cat ./fruit.toml
[fruit]
strawberries = 20
blueberries = 100

$ cat ./fruit.toml | yj -tj
{"fruit":{"strawberries":20,"blueberries":100}}

$ cat ./fruit.toml | yj -tj | yj -jt
[fruit]
strawberries = 20
blueberries = 100