String escaping and language fulltext search question

Hi, there. I am a beginner to dgraph club and I meet two problems when I learn and use dgraph.

The first one is, is there some way to handle character escaping. For example, quotation marks inside the string quotation marks. I’d like to store a JSON string as an attribute value. This will raise a mutation error.

The second one is, in Fulltext searching, is there any difference between indexing the predicates with language and mark @lang in my predicate when I create a mutation and not doing so, specifically non-English language.

Thanks a lot,

Hi @kehan1 welcome to Dgraph community.

first question
If we have a type like this:

type Something {
  SomethingID: ID!

I can add my JSON field like this:

mutation createSomething {
  addSomething(input: {jsonField: "{\"name\": \"Kehan\"}"}) {
    something {

And for example if I parse this string with Javascript JSON.parse:

JSON.parse("{\"name\": \"hasan\"}")

This will be the result: Object { name: "hasan" }

Second question
Having language index on your predicate will let you execute queries based on the language of inserted field. This article and video might help you with multi-language:

When you have a field that you want to fill it with different languages, by adding @lang index you can provide more information about the language. It is not related to full text search as far as I’m concerned but you can execute queries to find that field in specific language.

1 Like

Hi Poorshad, thanks for replying.
For more details about the first one besides JSON object, if I have a type Person, it has an attribute name, like the example below.

type Person{
name: string @index(hash) .

When I insert data like,

{ set {
    _:myName <name> " "Kehan" " .

this will raise a mutation error, so I am doing character escaping manually, like " “Kehan” ".
Is there any built-in method to take care of it? Like we have a parameter function to handle character escaping when we use DQL to search it, example below. This is a big problem for me since I have a big size of string data to insert. Except of quotation marks, \n/\r raises this error as well.

# reference from **
query = """query all($a: string) {
  all(func: eq(name, $a))
variables = {'$a': 'Alice'}

res = txn.query(query, variables=variables)


I have not seen a built-in function with this purpose. Which client do you use to insert your data?

I am using python to insert data, and js and python for searching.