cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

Large Numbers as strings

Open schmidtw opened this issue 4 years ago • 2 comments

I wanted to see if there would be any interest in accepting a patch where large numbers (like even larger than 64bit numbers) would be handled as a string in addition to a native type, or if large enough, just a string.

Why strings?

  • While generally not ideal for numbers, it's pretty easy to represent a 64 byte number as a string. The code that needs to handle the crazy number can deal with it vs. cJSON needing to.
  • Allows software that want 64bit number support to add it & deal with it outside cJSON while allowing cJSON to stay C89.
  • It looks like it would be pretty easy to add to the decoder (like a cJSON_strdup() call into item->valuestring)
  • I don't want to change code away from this library that is really solid just because I need to pass large numbers in a few specialized payloads (& that can't string encode them...)

schmidtw avatar May 12 '21 05:05 schmidtw

I went an wrote up what I had in mind & got the tests working as well. https://github.com/DaveGamble/cJSON/pull/580

schmidtw avatar May 12 '21 07:05 schmidtw

@Alanscut what do you think about this approach?

schmidtw avatar Oct 22 '21 06:10 schmidtw