🚀 New: Run requests via webhooks. Learn more

GraphQL to JSON Body Converter

Enter a GraphQL query to convert it to a JSON body for a POST request.

GraphQL Query
JSON Body

Why Convert GraphQL Query to JSON Body?

If you're connecting to a GraphQL server using HTTPS requests, the server probably expects you to send a POST request with the query in the JSON body like this:

{
  "query": "query { countries { code name emoji capital continent { name } currency } }"
}
So you need your GraphQL query to be in this format to send it to the server.

Unfortunately, most GraphQL API docs/ playgrounds just give you straight GraphQL queries like this:

query {
    countries {
      code
      name
      emoji
      capital
      continent {
        name
      }
      currency
    }
  }
You cannot use this directly in the request body as it is not valid JSON.

Converting a GraphQL query to a JSON body is simple. First, we remove new lines/ extra spaces from the GraphQL query. Then we add it under a "query" key in a JSON object. This is what the converter above does!

Sometimes, you will want to send the optional "operationName" and "variables" fields too. You can add these fields to the JSON yourself if you need them.

{
  "query": "query { countries { code name emoji capital continent { name } currency } }",
  "operationName": "...",
  "variables": { "myVariable": "someValue", ... }
}

Convert GraphQL Query to JSON Body Online

  1. Paste your GraphQL query into the 'GraphQL Query' input above.
  2. Your query will automatically be converted to a JSON body in the right hand input.
  3. Click the 'Copy' button to copy the JSON body to your clipboard.

Having trouble? Try clicking the 'Beautify' button to validate and format your query. You will be shown any errors.