Skip to content

Boolean in Json #13

Description

@kovacskor

Hi Guys,

I started to use your library, I like is a lot because of it's simplicity and lightness.
I've encountered an issue though, when I need to deserialize a json and retrieve a bool value it seems not to work.
Example json:
{"_id":"637a8b27171c8e5a9","name":"somename","type":"a4","apikey":"someapikey","deviceid":"a48003cb","createdAt":"2022-11-20T20:16:35.783Z","online":true}

example code:
void setup() {
Serial.begin(115200);
String test_json = "{"_id":"637a8b27171c8e5a9","name":"somename","type":"a4","apikey":"someapikey","deviceid":"a48003cb","createdAt":"2022-11-20T20:16:35.783Z","online":true}";
delay(5000);

Serial.println(jsonExtract(test_json, "name")); // result is somename which is good :)
Serial.println(jsonExtract(test_json, "online"));
}

// result is {"_id":"637a8b27171c8e5a9","name":"somename","type":"a4","apikey":"someapikey","deviceid":"a48003cb","createdAt":"2022-11-20T20:16:35.783Z","online":

I was in a hurry so what I did to resolve it is added a few lines to jsonlib.cpp from line 120:

// bool
else if(json.substring(start, start + 4) == "true"){
stop = start + 4;
}
else if (json.substring(start, start + 5) == "false"){
stop = start + 5;
}

This way it interprets bool now.

Please let me know if there is an another way to do that.

Thanks in advance,
Kornel

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