Can't store JSON as string DQL

I’m trying to store a certain payload as a string using DQL, using the dgraph-js library.

To do this what I do is JSON.stringify(payload), which if the payload is the following object {hello: "bye"}, it will create the following string "{\"hello\": \"bye\"}".

Nevertheless, the problem is that dgraph does not allow strings containing the { character. I tried to escape every { and } using the following line

jsonPayload.replace(/[{}]/, (v) => `\\${v}`)

This creates the following string "\{\"hello\": \"bye\"\}". But when trying to execute the mutation, dgraph escapes the \, thus still having the error because the { are not escaped.

What can it be done?


The problem is not the bracket but the escape quotes. Double escape them.