Skip to content
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

Two blackslashes on json output file #1253

Closed
exphck1337 opened this issue Sep 21, 2018 · 3 comments
Closed

Two blackslashes on json output file #1253

exphck1337 opened this issue Sep 21, 2018 · 3 comments
Labels
solution: invalid the issue is not related to the library

Comments

@exphck1337
Copy link

It has a small bug in the library, recognizing two backslashes in the output(which should only be one in this case):

// Bug example:
bool write_default_config() {
  auto default_config_file = std::ofstream(config::get_config_file_full_dir());

  if (default_config_file.is_open()) {
    json default_config = {{"steam_path", "C:\\Program Files (x86)\\Steam"}, // I need to use \\ because it is a backslash character, using only \ the compiler doesn't recognize as a backslash character
                     {"clear_appcache", true},
                     {"execute_bcdedit", true},
                     {"execute_sfc", true},
                     {"repair_steamservice", true}};

    default_config_file << default_config.dump(10) << std::endl;
    default_config_file.close();
    return true;
  }
  return false;
}

Output in .json file:

{
          "clear_appcache": true,
          "execute_bcdedit": true,
          "execute_sfc": true,
          "repair_steamservice": true,
          "steam_path": "C:\\Program Files (x86)\\Steam"
}

Correct output should be:

{
          "clear_appcache": true,
          "execute_bcdedit": true,
          "execute_sfc": true,
          "repair_steamservice": true,
          "steam_path": "C:\Program Files (x86)\Steam"
}

Is there any way to show only one backslash instead of two on output?

@nlohmann
Copy link
Owner

This is not a bug. Backslashes must be escaped in JSON strings, see json.org.

@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Sep 21, 2018
@exphck1337
Copy link
Author

Okay, I'm starting with json, sorry for that.

Thanks for the answer.

@nlohmann
Copy link
Owner

No worries! Feel free to ask any questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants