Search code examples
jsonrawstring

Raw string field value in JSON file


In my JSON file, one of the fields has to carry the content of another file (a string).

The string has CRLFs, single/double quotes, tabs.

Is there a way to consider my whole string as a raw string so I don't have to escape special characters?

Is there an equivalent in JSON to the string raw delimiter in C++?

In C++, I would just put the whole file content inside : R"( ... )"


Solution

  • Put simply, no there isn't. Depending on what parser you use, it may have a feature that allows this and/or there may be a variant of JSON that allows this (examples of variants include JSONP and JSON-C, though I'm not aware of one specifically that allows for the features you are looking for), but the JSON standard ubiquitous on the web does not support multiline strings or unescaped special characters.