-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON Parse error when reading json object from file #3011
Comments
The stacktrace mentiones flagValue = jReadObj[flagName].get<bool>(); fails. Can you replace it to flagValue = jReadObj.at(flagName).get<bool>(); to actually throw an exception? Using |
Thank You for the response, I will give it a try. |
You can parse strings like this: json j = json::parse("[1,2,3]"); Or what do you mean? |
As per the examples shared in ReadMe, the string can be converted to a JSON object by using the below format In the problem use case, the library call returns a char * which is then passed to json::parse before assigning to a JSON object. |
The const char* s = some_function_returning_a_c_string();
json j = json::parse(s); |
Closed the ticket as I received the information looking for. |
Observing random crash when reading JSON file data to a JSON object. Here is the summary of the crash. The crash point is always consistent.
Description:
One process takes care of the following:
[Library Call] --> Returns serialised JSON key-value pair as char *, which is placed in std::string Example : std:string testString = libCall(); testString now holds a string like this {"IS_JSON_FLAGON": true}
To ensure there are no additional characters and to adhere to the JSON object compatibility, the std::string is parsed and then assigned to a JSON object
Example: nlohmann::json jWriteObj = nlohmann::json::parse(testString .c_str());
The JSON object is then written to JSON file
Example :
this creates/updates the file with .json extension Example: flagsFile.json with data {"IS_JSON_FLAGON":true}
In another process, the file written by the previous process is read
Modules want to know the Flag value, so calls isFlagOn("IS_JSON_FLAGON") which then opens the file and reads the data to a json object
Example: [Module reading the flag value] ---->isFlagOn("IS_JSON_FLAGON") definition for isFlagOn()
The crash is very random on Ubuntu 20.04 and points to the line highlighted. The surprising part is the exception is not getting caught in spite of using the wildcard exception approach
Any suggestions on what needs to be corrected in this would help.
Snippet of crash:
#5 0x00007fe72ed436a9 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x000055fa7315cae9 in nlohmann::basic_json<std::map, std::vector, std::string, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>::operator[] (this=0x7fe67dff8840, key=0x55fa7385c64a
We are using nlohmann version 3.7.3 in our product
The text was updated successfully, but these errors were encountered: