-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
In compatible JSON object from nlohmann::json to nohman::json - unexpected end of input; expected '[', '{', or a literal #1603
Comments
Is this related to #1583? |
@nickaein no tried that already. The problem in the issue you reference was for writing JSON and then reading it again, and the issue was due to mis-match in character encoding. Which from what I can tell is not the case this time. |
Is the file accessible? Try with its absolute path. BTW, I don't get any error for this program ( #include "json.hpp"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
try
{
nlohmann::json j;
std::ifstream fs("input.json");
if(!fs)
{
std::cout << "Failed to open file" << endl;
return 0;
}
fs >> j;
std::cout << "Success." << endl;
std::cout << "Raw content:" << endl;
std::cout << j.dump(4) << endl;
std::cout << "Retrieved configs:" << endl;
std::cout << "\tbase_out_path: " << j["base_out_path"].get<std::string>() << endl;
std::cout << "\tbase_register_path: " << j["base_register_path"].get<std::string>() << endl;
std::cout << "\tout_path: " << j["out_path"].get<std::string>() << endl;
std::cout << "\tregister_path: " << j["register_path"].get<std::string>() << endl;
std::cout << "\tmax_registry_size: " << j["max_registry_size"].get<size_t>() << endl;
}
catch(std::exception& e)
{
std::cout << "Exception:" << endl;
std::cout << e.what() << endl;
return 0;
}
return 0;
} It might help to debug the error. For me, it outputs the following as expected:
|
I triede you code above and it works. Now I tried writing it to disk as well and reading into a new object also gives and error and again this is not an issue with reading the file. This is an issue when parsing around the object |
Okay, I have actually gotten a bit further if the first string: minerva_config["register_path"] = (USER_HOME + minervafs_root_folder + minervafs_identifier_register); resolves to What is this wizardry ??? identifiers |
That's weird. Can you provide a minimal working code that demonstrates this error? Also, are you using the same file handler for writing and reading the config file? If so, you might need to rewind it (e.g. |
@nickaein there is no file invovled this is just for the |
I see, but the exception in #1603 (comment) usually is thrown when parsing, whether it is parsing the file stream or an string. Are you still getting this exception? For instance, passing an empty string to One other case that this type of exception can be thrown is during the construction of a A minimal code to demonstrate the problem you are having would be very helpful! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hey I am trying to create a configuration using
nlohmann::json
, but for some reason I get:I have create a JSON object with
nlohmann::json
like thisThe
json_writer
does not fail, what fails is the construct on the next line. Which gives the error presented above. I have tried to remove the writer call but no dice. The code for the constructor is like this:Where it it interact with the
nlohmann::json
object. As I am within the same application I wouldn't assume system char encoding or something like that is a problem.I tried to dump the json object and passed it in a JSON validator, the dump is as follows:
Any ideas as to what might be wrong?
The text was updated successfully, but these errors were encountered: