Introduction

Ah, GraphQL and JSON, the dynamic duo of the modern web! If you’ve ever found yourself tangled in the web of APIs, you know these two are like Batman and Robin. But what happens when you need to convert a GraphQL request into a JSON object? Buckle up, because we’re about to embark on a journey that’s as enlightening as it is entertaining!

Problem

Imagine you’re a developer (or maybe you are one, in which case, kudos!). You’ve got your GraphQL query, and it’s a beauty.

query {
  user(id: "1") {
    name
    email
    friends {
      name
    }
  }
}

But wait! Your boss (or client, or receiver side) wants this data in a JSON object. No problem, right? Let’s get to it.

Solution

You just need to convert json format request similar as below

{
  "query": "{  user(id: \"1\") {    name    email    friends {  name  }  } }"
}

This should work as Charm!!

By htlwebs

Leave a Reply

Your email address will not be published. Required fields are marked *