New topic Closed topic
avatar image
1
How to escape/encode literal backslashes when retrieved as JSON object?
By Created , last editted

Hi all,

I've been running some tests with retrieving string data (of data type Text (single line)) as JSON objects. I noticed that literal backslashes are not escaped, therefore resulting in an invalid JSON object.

For example:

Database value: "test with literal backslash \"

JSON result: "test with literal backslash \"

Correct JSON would be: "test with literal backslash \\" or

"test with literal backslash \​​"​

I tried: "name":"{{myvalue | replace:'\', '\\' }}" 

JSON result of replace pipe is : "test with literal backslash \"

Please note that when a text field contains the literal text "\n" or "\t", this will be translated to newline and tab in JSON .

How can I make sure that literal backslashes in text fields are escaped or encoded when retrieving the data as JSON object?


Hi all,

I've been running some tests with retrieving string data (of data type Text (single line)) as JSON objects. I noticed that literal backslashes are not escaped, therefore resulting in an invalid JSON object.

For example:

Database value: "test with literal backslash \"

JSON result: "test with literal backslash \"

Correct JSON would be: "test with literal backslash \\" or

"test with literal backslash \​​"​

I tried: "name":"{{myvalue | replace:'\', '\\' }}" 

JSON result of replace pipe is : "test with literal backslash \"

Please note that when a text field contains the literal text "\n" or "\t", this will be translated to newline and tab in JSON .

How can I make sure that literal backslashes in text fields are escaped or encoded when retrieving the data as JSON object?

Answers
Sort by:

This topic is closed.