Skip to content

JSON integer mangling #807

Description

@nnposter

Function json.generate is using string.format("%g", obj) to convert numbers to strings. This has an undesired effect of mangling longer integers as follows:

obj = {session=1684119503}
json.make_object(obj)
str = json.generate(obj)

String str is now {"session": 1.68412e+009}.

I wonder if it would be more appropriate to use tostring(obj), which does not have this side-effect.

Digging into the history, the "%g" conversion has been there since the initial json.lua commit by David in 2010 (r16896).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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