Skip to main content

Why do I need to convert my GraphQL query into a one-line string?

When sending GraphQL requests through web-based clients or tools, the query field must be a valid JSON string. That means the entire GraphQL query must be on one line, and all double quotes " inside the query need to be escaped (e.g., \"). This ensures the JSON remains valid and can be parsed correctly.

How can I easily convert my multi-line playground query into the one-line web format?

The simplest method is using jsonblob.com:
  1. Go to jsonblob.com
  2. Click CLEAR to reset the view
  3. In the left panel, paste query:
    { "query": "" }
    
    
  4. In the right panel, scroll until you see the Value field
Jsonblobvaluefield Jp
  1. Paste your full GraphQL playground query into the Value field.
  2. The left panel automatically updates with the properly escaped one-line string.
Jsonblobresultescapedqueryoneline Pn That output is exactly what you should send as your request payload.

What does the conversion actually do?

It turns this:
mutation {
  Position(id: "623c66b61df8a64c6648f702a") {
    invite(candidate: { name: "Daniela", email: "daniela@hireflix.com" }) {
      id
      url {
        public
        short
      }
    }
  }
}
Into this:
{
  "query": "mutation {\n Position(id: \"623c66b61df8a64c6648f702a\") {\n invite(candidate: { name: \"Daniela\", email: \"daniela@hireflix.com\" }) {\n id\n url {\n public\n short\n }\n }\n }\n}"
}
All quotes are escaped, and all line breaks are encoded as \n.