Skip to content

Float keys are encoded as ints #36

Open
@cvermilion

Description

Relevant code, I think: https://github.com/cognitect/transit-js/blob/master/src/com/cognitect/transit/handlers.js#L126-L128

Encoding {1.5: 3.14} results in (verbosely) "{\"~i1.5\":3.14}", instead of "{\"~d1.5\":3.14}", so it round-trips to {1: 3.14}.

I think a fix would just involve setting the tag above based on whether the Number is an int. Naturally JavaScript has no built-in way to do this, though. I'm not much of a JS guy, but maybe Math.round(x) === x would do?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions