opto.trace.utils.escape_json_nested_quotes#
- escape_json_nested_quotes(json_str)[source]#
Escapes double quotation marks inside JSON string values for a specific format: {“name”: “string value”, “value”: “string value”} Does not escape quotes around keys or structural quotes.
Warning
Here are what this function does not do: 1. Cannot handle “n” or “t” type of strings 2. Does not check if “n”, “t”, or other control characters are properly escaped. Please use json_str.replace(”n”, “n”) to escape control characters outside of this function.
Example usage can be found in optimizers/textgrad.py.
- Parameters:
json_str (str) – A string representation of JSON with exactly two keys: name and value.
- Returns:
JSON string with properly escaped quotes in values.
- Return type:
str