-
-
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
Setting values of .JSON file #1444
Comments
Assume your JSON file is called std::ifstream input_file("file.json");
json j;
input_file >> j; Then you can access the value with j["Settings"]["AutoReload"] = false; |
Okay. But question is about can I rewrite and save JSON file with the new value? Or I can work only with gotten value, can't set it? |
Do you mean how to write a JSON value (like |
Yes, but only this value. Other values should not be changed if user didn't set them. Only needed value should be rewrited in JSON file. |
I do not understand. How should the expected JSON file look like? |
I'm sorry. For example, this's current JSON file The user wanna set the value of "Settings - AutoReload", set it from "True" to "False" and save it by rewriting JSON file with the new value. The new JSON file will look like As you can see, other value of "Settings - CheckingUpdates" was not touched, because user didn't set it. In short - can I work and rewrite only a specific value? Can I rewrite the file, changed "Settings - AutoReload" value to "True" and didn't touched "Settings - CheckingUpdates" value ? Or should I use INI or something another for this purpose? |
So you want to write the complete changed value // read
std::ifstream input_file("file.json");
json j;
input_file >> j;
// change
j["Settings"]["AutoReload"] = false;
// write
std::ofstream output_file("new_file.json");
j >> output_file; The content of that file should be {"Settings":{"AutoReload":false,"CheckingUpdates":false}} |
Thank you very much. |
This is example of my .JSON file.
{"Settings":{"AutoReload":true,"CheckingUpdates":false}}
What function should I use to set the value of "Settings-AutoReload" from "True" to "False", for example? To set and save it.
The text was updated successfully, but these errors were encountered: