Raw string field value in JSON file
Asked Answered
B

2

10

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

Beckwith answered 5/6, 2018 at 18:55 Comment(0)
A
9

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.

Almund answered 5/6, 2018 at 19:1 Comment(0)
C
5

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

Comet answered 14/6, 2019 at 3:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.