"set" mutation escape character in JSON error

Hi,

I’m playing around with Dgraph and tried to insert some test data into Dgraph using cURL but I’m getting an error on a value containing escape characters.

JSON:

{
  "set": {
    "dgraph.type":"Update",
    "title":"TEST - Data Science vs. Machine Learning vs. Artificial Intelligence - DATAVERSITY",
    "url":"https://www.dataversity.net/data-science-vs-machine-learning-vs-artificial-intelligence/",
    "key":"https://www.dataversity.net/data-science-vs-machine-learning-vs-artificial-intelligence/",
    "type":"web",
    "source":"Google Alert - \"data science\"",
    "date_published":"2019-10-01T08:50:07+00:00",
    "timestamp_imported":"2019-10-14T10:47:08.539237",
    "keywords":["artificial intelligence","data science","machine learning","intelligence","science"]
  }
}

Returns:

{
  "errors": [
    {
      "message": "invalid character 'd' after object key:value pair",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ]
}

Removing the “source” key and value results in a successful mutation, so my guess is that something is going wrong with the escape characters in the value.

A quick test using Ratel UI does successfully process:

{
  set {
    _:up <source> "Google Alert - \"data science\"" .
  }
}

(The JSON keys+values are generated from a POJO using Gson, if that matters)

Perhaps I’m doing something wrong?

Also, if you send the JSON you’ve shared works fine in the Ratel UI.

I don’t think so, I think this is a parser error in cURL.

You can solve this by double escaping it:

curl -H "Content-Type: application/json" -X POST localhost:8080/mutate?commitNow=true -d  $'
    {
      "set": [
        {
		  "dgraph.type": "Update",
          "title": "TEST - Data Science vs. Machine Learning vs. Artificial Intelligence - DATAVERSITY",
		  "url": "https://www.dataversity.net/data-science-vs-machine-learning-vs-artificial-intelligence/",
		  "key": "https://www.dataversity.net/data-science-vs-machine-learning-vs-artificial-intelligence/",
		  "type": "web",
		  "source": "Google Alert - \\\"data science\\\"",
		  "date_published": "2019-10-01T08:50:07+00:00",
		  "timestamp_imported": "2019-10-14T10:47:08.539237",
		  "keywords": ["artificial intelligence","data science","machine learning","intelligence","science"]
        }
      ]
    }' | jq

Cheers.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.