hasura/graphql-engine · error · Error
unable to serialize to json: {0}
Error message
unable to serialize to json: {0} What it means
Serializing the introspection response to JSON failed (serde_json::Error). The introspection result could not be written to JSON, usually because a value in the schema response is not JSON-representable or contains an invalid value (e.g. invalid UTF-8 string in a name/description).
Source
Thrown at v3/crates/graphql/lang-graphql/src/generate_graphql_schema.rs:23
use json_ext;
use std::collections::BTreeMap;
use std::sync::OnceLock;
use tracing_util::SpanVisibility;
use tracing_util::{ErrorVisibility, TraceableError};
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("unable to parse introspection query: {0}")]
ParseIntrospectionQuery(String),
#[error("unable to normalize introspection query: {0}")]
NormalizeIntrospectionQuery(String),
#[error("unable to find field call")]
FieldCallNotFound,
#[error("Only __schema field is expected but found: {name:}")]
OnlySchemaFieldExpected { name: String },
#[error("introspection query failed: {0}")]
IntrospactionQueryError(#[from] crate::introspection::Error),
#[error("unable to serialize to json: {0}")]
SerializeJson(#[from] serde_json::Error),
}
impl TraceableError for Error {
fn visibility(&self) -> ErrorVisibility {
ErrorVisibility::User
}
}
/// Generate GraphQL schema for a given namespace
pub fn build_namespace_schema<
S: crate::schema::SchemaContext,
NSGet: crate::schema::NamespacedGetter<S>,
>(
namespaced_getter: &NSGet,
schema: &crate::schema::Schema<S>,
) -> Result<serde_json::Value, Error> {
let tracer = tracing_util::global_tracer();
tracer.in_span(View on GitHub (pinned to 724551b9ae)
Solutions
- Check the inner serde_json error to find the offending value
- Fix invalid UTF-8 or unserializable content in schema names/descriptions/metadata
- Regenerate metadata from clean sources
Defensive patterns
Strategy: try-catch
Validate before calling
// Validate metadata strings are valid UTF-8 before applying
if (!Buffer.from(name, 'utf8').toString('utf8') === name) throw new Error('bad encoding'); Type guard
const isSafeUtf8 = (s) => { try { new TextEncoder().encode(s); return s === new TextDecoder().decode(new TextEncoder().encode(s)); } catch { return false; } }; Try / catch
// Catch, read the serde_json inner error to locate the unserializable value
Prevention
- Keep descriptions/names in valid UTF-8
- Source metadata from clean files
When it happens
Trigger: Executing introspection on a schema whose names or descriptions contain invalid UTF-8 or other non-serializable content; map keys colliding in an unexpected way in the response.
Common situations: Metadata descriptions sourced from files with bad encodings; schema strings built from raw byte data.
Related errors
- unable to fetch introspection schema: %w
- error in fetching introspection schema: %w
- %s: %d %s
- %s: decoding graphql response errors: %w
- %s: %w
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/e6475a90653d2536.
Report an issue: GitHub.