Search code examples
jsonredisbackslash

Redis adds "\" to JSON string


I am using ServiceStack Redis to save a value of a JSON and retrieve it later. The problem is when i retrieve the value from the redis, it adds multiple "\" and that ruins my JSON.

for example i save:

{ "user": "123456", "password": "xxxxxxx" }

and when i retrieve the value it comes out:

{ \"user\": \"123456\", \"password\": \"xxxxxxx\" }

i was wondering if there is some kind of setting to prevent that? why does it happen? The JSON contains some "\n" characters that get "\" added to them as well, i just removed them from the example to make it more readable.


Solution

  • After checking my code, i noticed that i am type casting to string when returning the data from the Redis (which is returned as a byte array), and it was adding the extra "\". My solution for the problem was decoding my JSON to a base64String before storing it in the Redis and then decoding it back.