JSON Utilities
This module provides functions for processing JSON strings. It supports:
- Removing comments from JSON strings.
- Handling JSON configurations with comments.
Key Functions:
strip_json_comments
: Removes comments from a JSON string.
check_escaped
: Checks if a character is escaped (used internally by strip_json_comments
).
Example:
std::string raw_json = R"({
"key": "value", // This is a comment
/* Another comment *‍/
"key2": "value2"
})";
std::cout << "Clean JSON: " << clean_json << std::endl;
return 0;
}
Utilities for working with JSON strings, including removing comments.
*The resulting JSON string may optionally retain whitespace or newlines *where the comments were removed **param json_string The JSON string to process *param with_whitespace If comments are replaced with equivalent whitespace *If comments are removed without leaving whitespace *param preserve_newlines If true and with_whitespace is newline characters *in comments are preserved all characters in the *comments are replaced with whitespace *return A JSON string with comments removed *std::string strip_json_comments(const std::string &json_string, bool with_whitespace=false, bool preserve_newlines=true)