Search code examples
c++jsontypesjsoncpp

Differentiate between int and uint type in jsoncpp


I'd like to parse some json data after reading it with jsoncpp which differentiates between int and uint data type.

The meaning of these types is clear to me, but when I read data like value: 7, jsoncpp recognizes this as int. Of course, value may also be negative in a different situation but if jsoncpp only knows the current situation why doesn't it parse value as uint?

Valid jsoncpp types are listed here. I check the type like this:

switch(root->type()) {
    case Json::intValue:    serializeInt(root->asInt(), key);       break;
    case Json::uintValue:   serializeUInt(root->asUInt(), key);     break;

Only the int case is executed.

So my question basically is, how can I express in json that a value is unsigned so that jsoncpp parses it like this?


Solution

  • jsoncpp uses unsigned int when the value doesn't fit in int.

    You might try with value like INT_MAX + 1.