Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raw string field value in JSON file

Tags:

json

rawstring

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"( ... )"

like image 750
hamza keurti Avatar asked Jun 05 '18 18:06

hamza keurti


2 Answers

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.

like image 56
Shaun Hamman Avatar answered Sep 30 '22 18:09

Shaun Hamman


A workaround for the lack of raw string support in JSON is to Base64 encode your string before adding it to your JSON.

like image 38
rancidfishbreath Avatar answered Sep 30 '22 19:09

rancidfishbreath