hashicorp / hashicorp/consul-template
parseJSON | toTOML incorrectly casts integers to float
- Dominant language
- Go
- Stars
- 4.8k
- Forks
- 801
- Avg merge
- 4h 5m
- Merged PRs (30d)
- 6
Description
Tested with Consul v0.22.0
When using the parseJSON and toTOML functions together, integers are incorrectly cast to floats
The following template:
```
{{ scratch.MapSet "vars" "foo" 1 }}
{{ scratch.Get "vars" | toJSON }}
{{ scratch.Get "vars" | toTOML }}
{{ scratch.Get "vars" | toJSON | parseJSON | toTOML }}
{{ $json := "{\"foo\": 1}" }}
{{ $json }}
{{ ($json | parseJSON).foo }}
{{ $json | parseJSON | toTOML }}
```
Produces this output:
```
{"foo":1}
foo = 1
foo = 1.0
{"foo": 1}
1
foo = 1.0
```
I have not tested on earlier versions of consul-template.
As a workaround, I've been using regexReplaceAll to strip floating 0s.
```
{{ $json | parseJSON | toTOML | regexReplaceAll "\\.0\n" "\n" }}
```
Contributor guide
Assessment
This issue has not been assessed yet.