json-rust icon indicating copy to clipboard operation
json-rust copied to clipboard

Feature Request: floating point precision

Open njaard opened this issue 7 years ago • 5 comments

When I dump my json object, I would like to control how much precision it outputs with. This is useful because as a transit format, I don't want huge payloads because I'm printing 12 digits of my floats.

Maybe a good way to implement this is supporting decimal real numbers from some other crate.

njaard avatar Jan 24 '18 15:01 njaard

This is also important for sending stuff to Elasticsearch, which doesn't accept floating point values without a decimal point.

njaard avatar Apr 23 '18 14:04 njaard

This is also important for sending stuff to Elasticsearch, which doesn't accept floating point values without a decimal point.

You mean it doesn't accept 10 as 10.0? How do they handle JSON produced by JavaScript builtins?

maciejhirsz avatar Apr 27 '18 14:04 maciejhirsz

You mean it doesn't accept 10 as 10.0?

Yes, that's what I mean. If ES decides that a field a floating point value, it won't accept things that look like integers in that field.

How do they handle JSON produced by JavaScript builtins?

I don't know

njaard avatar Apr 27 '18 14:04 njaard

That's a rather strange design decision, JSON has no concept of floats or integers (in fact the actual number format is so loosely defined it could mean anything). I'm asking about the JS because it's impossible to produce something like {"num":10.0} with JSON.stringify().

maciejhirsz avatar Apr 27 '18 16:04 maciejhirsz

This is the error ES gives you:

{ "type": "illegal_argument_exception", "reason": "mapper [column_name] of different type, current_type [float], merged_type [ObjectMapper]"}

njaard avatar Apr 28 '18 10:04 njaard