You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Float numbers in JSON stdout and http output plugin misformatted #6447
Describe the bug
Hi, I noticed certain float numbers such as 0.072 in a JSON data structure is being rewritten as 0.07199999999999999 when using the Format json option for the stdout and http output plugin.
I am sending out logs to a service that only accepts numbers with Decimal positions to be less than 16 digits. I am unable to find a way to preserve the number as-is when using the Format json option through the output plugins.
Any help with a fix/workaround is much appreciated!
To Reproduce
Rubular link if applicable:
Example log message if applicable:
{"test": 0.072}
Steps to reproduce the problem:
tail.conf
[SERVICE]
Parsers_File parsers.conf
Flush 0.1
[INPUT]
Name tail
Path /test.log
Parser json
[OUTPUT]
Name stdout
Match *
Format json
json_date_key false
parsers.conf
[PARSER]
Name json
Format json
test.log
{"test": 0.072}
Setup environment with files listed above.
Run following command in terminal where tail.conf is located: fluent-bit -c tail.conf
Run the following command in a new terminal where test.log is located: echo '{"test": 0.072}' >> test.log
Expected behavior
Expect output to be [{"test":0.072}] instead of [{"test":0.07199999999999999}].
Your Environment
Version used: Fluent Bit v2.0.4
Configuration:
Environment name and version (e.g. Kubernetes? What version?):
Server type and version:
Operating System and version: MacOS Monterey v12.6
Filters and plugins: tail Input plugin, JSON parser plugin, stdout Output plugin, and HTTP Output plugin
Additional context
Possibly, allow an option to preserve the number types without being reformatted when parsing.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days. Maintainers can add the exempt-stale label.
This is still reproducible on current master — the Format json path in flb_pack.c still uses %.16g, so 0.072 serializes as 0.07199999999999999.
I've opened #12129 with a fix: a shared flb_pack_double_to_str() helper that uses the already-vendored yyjson dtoa to emit the shortest decimal string that round-trips back to the same double (so 0.072 → "0.072"), while still guaranteeing round-trip precision (unlike a plain %.15g). Non-finite values keep their previous formatting.
Could a maintainer please reopen this issue? Thanks to @nokute78 for pinpointing the %.16g root cause.
Activity
nokute78 commentedon Nov 26, 2022
Note: The issue is related
%.16g.https://github.com/fluent/fluent-bit/blob/v2.0.6/src/flb_pack.c#L596
Related PR:
#1439
#2592
github-actions commentedon Feb 24, 2023
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days. Maintainers can add the
exempt-stalelabel.github-actions commentedon Mar 1, 2023
This issue was closed because it has been stalled for 5 days with no activity.
vitaly-sinev commentedon Jul 21, 2026
This is still reproducible on current
master— theFormat jsonpath inflb_pack.cstill uses%.16g, so0.072serializes as0.07199999999999999.I've opened #12129 with a fix: a shared
flb_pack_double_to_str()helper that uses the already-vendored yyjson dtoa to emit the shortest decimal string that round-trips back to the same double (so0.072→"0.072"), while still guaranteeing round-trip precision (unlike a plain%.15g). Non-finite values keep their previous formatting.Could a maintainer please reopen this issue? Thanks to @nokute78 for pinpointing the
%.16groot cause.pack: format JSON floats using shortest round-trip representation
tests: internal: pack: add float round-trip formatting test
pack: format JSON floats using shortest round-trip representation
tests: internal: pack: add float round-trip formatting test
pack: format JSON floats using shortest round-trip representation
tests: internal: pack: add float round-trip formatting test
pack: format JSON floats using shortest round-trip representation
tests: internal: pack: add float round-trip formatting test
pack: format JSON floats using shortest round-trip representation
tests: internal: pack: add float round-trip formatting test
pack: format JSON floats using shortest round-trip representation
tests: internal: pack: add float round-trip formatting test
pack: format JSON floats using shortest round-trip representation
tests: internal: pack: add float round-trip formatting test