GraphQL from a JSON Perspective
2025-12-15
Evolution of Data Fetching
In traditional REST APIs, the JSON structure is fixed by the server. GraphQL allows clients to specify exactly what fields they need using a JSON-like query language.
Query Example
{
user(id: "1") {
name
friends {
name
}
}
}
Response
The response strictly follows the query structure:
{
"data": {
"user": {
"name": "Alice",
"friends": [{ "name": "Bob" }]
}
}
}
Type System and JSON
GraphQL's strong type system addresses JSON's loose typing. The Schema Definition Language (SDL) defines types for every field, ensuring contract certainty.
Performance Considerations
- Avoid Over-fetching: Fetch only what is needed, reducing payload size.
- Avoid Under-fetching: Get related data in a single request, reducing RTT.
Summary
GraphQL combines JSON's flexibility with a strong type system, providing a more efficient solution for data interaction in complex applications.