0

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?

lukasl1991
  • 241
  • 3
  • 11

1 Answers1

2

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

You might try with value like INT_MAX + 1.

Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • Yes, this produces an `uint`. This wasn't obvious to me. Thanks! So there is no possibility in `json` to say that a value that fits into an `int` should be treated as `uint`? – lukasl1991 Apr 25 '19 at 13:19
  • 1
    The `json`'s spec only has *Number*, it doesn't have `int`, `uint`, `double` (but C++ has). So from json, you can't, but from `jsoncpp`, you might be able to, but information would be lost anyway once exported to json. – Jarod42 Apr 25 '19 at 13:26