pelletier / go-toml

Go library for the TOML file format
https://github.com/pelletier/go-toml
Other
1.69k stars 206 forks source link

jsontoml - integers become floats #824

Closed rleap-m closed 1 year ago

rleap-m commented 1 year ago

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

moorereason commented 1 year ago

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

rleap-m commented 1 year ago

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

rleap-m commented 1 year ago

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