Description
When converting YAML to JSON with -o json, whole-number float values like 50.0 are output as integers (50). This loses type information that YAML explicitly preserves via the !!float tag.
Reproduction
# test.yaml
percentiles:
- 50.0
- 95.0
- 99.0
- 99.9
$ yq -o json '.' test.yaml
Expected output
{
"percentiles": [
50.0,
95.0,
99.0,
99.9
]
}
Actual output
{
"percentiles": [
50,
95,
99,
99.9
]
}
Impact
This creates mixed-type lists in JSON (3 integers + 1 float) from what was a uniform float list in YAML. Downstream consumers that enforce uniform list types reject the output. For example, the Horreum performance data store rejects payloads containing mixed int/float lists.
In our case, YAML output from the Arcaflow engine correctly contains 50.0, but post-processing with yq -o json truncates these to 50, requiring a Python workaround to re-coerce them back to floats.
Environment
- yq version: v4.44.6 and v4.45.4 (tested both, same behavior)
- OS: Linux (aarch64)
Notes
While JSON's number type doesn't formally distinguish integers from floats, most JSON encoders (including Go's encoding/json, Python's json, and jq) do preserve 50.0 as a float in output. YAML explicitly tags these values as !!float, so the type information is available to yq during conversion.
Description
When converting YAML to JSON with
-o json, whole-number float values like50.0are output as integers (50). This loses type information that YAML explicitly preserves via the!!floattag.Reproduction
$ yq -o json '.' test.yamlExpected output
{ "percentiles": [ 50.0, 95.0, 99.0, 99.9 ] }Actual output
{ "percentiles": [ 50, 95, 99, 99.9 ] }Impact
This creates mixed-type lists in JSON (3 integers + 1 float) from what was a uniform float list in YAML. Downstream consumers that enforce uniform list types reject the output. For example, the Horreum performance data store rejects payloads containing mixed
int/floatlists.In our case, YAML output from the Arcaflow engine correctly contains
50.0, but post-processing withyq -o jsontruncates these to50, requiring a Python workaround to re-coerce them back to floats.Environment
Notes
While JSON's
numbertype doesn't formally distinguish integers from floats, most JSON encoders (including Go'sencoding/json, Python'sjson, andjq) do preserve50.0as a float in output. YAML explicitly tags these values as!!float, so the type information is available to yq during conversion.