{"record":{"id":"4ddb63bb1c9c02bf","repo":"hasura/graphql-engine","slug":"expected-session-variable-session-variable-to-be","errorCode":null,"errorMessage":"Expected session variable {session_variable} to be a valid JSON value, but encountered a JSON parsing error: {parse_error}","messagePattern":"Expected session variable (.+?) to be a valid JSON value, but encountered a JSON parsing error: (.+?)","errorType":"validation","errorClass":"InternalDeveloperError","httpStatus":null,"severity":"error","filePath":"v3/crates/plan/src/error.rs","lineNumber":61,"sourceCode":"    },\n\n    #[error(\n        \"Session variable {session_variable} value is of an unexpected type. Expected: {expected}, but found: {found}\"\n    )]\n    VariableTypeCast {\n        session_variable: SessionVariableName,\n        expected: String,\n        found: String,\n    },\n\n    #[error(\n        \"Typecasting session variable {session_variable} to an array is not supported. Update your compatibility date to enable JSON session variables\"\n    )]\n    VariableArrayTypeCastNotSupported {\n        session_variable: SessionVariableName,\n    },\n\n    #[error(\n        \"Expected session variable {session_variable} to be a valid JSON value, but encountered a JSON parsing error: {parse_error}\"\n    )]\n    VariableExpectedJson {\n        session_variable: SessionVariableName,\n        parse_error: serde_json::Error,\n    },\n\n    #[error(\"Type mapping not found for the type name {type_name:}\")]\n    TypeMappingNotFound {\n        type_name: Qualified<CustomTypeName>,\n    },\n\n    #[error(\"Field mapping not found for the field {field_name:} of type {type_name:}\")]\n    FieldMappingNotFound {\n        type_name: Qualified<CustomTypeName>,\n        field_name: FieldName,\n    },\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/plan/src/error.rs#L43-L79","documentation":"A session variable was expected to contain valid JSON (because it is used as a JSON value, e.g. cast to an array/object), but parsing it as JSON failed. The underlying serde_json parse error is included.","triggerScenarios":"Casting or consuming a session variable as a JSON value where the raw string is not valid JSON — e.g. x-hasura-roles containing 'admin;user' instead of '[\"admin\",\"user\"]'.","commonSituations":"Header-encoded lists using commas/semicolons instead of JSON arrays; truncated or quoted-wrong values from auth webhooks; clients not updated after a preset switched to JSON format.","solutions":["Fix the client/auth layer to send a syntactically valid JSON value for that variable (quote strings, bracket arrays)","Validate the variable server-side before the request (auth webhook) with a JSON parse check","If JSON isn't actually needed, remove the JSON/cast usage and treat it as a plain string"],"exampleFix":"# before\nx-hasura-roles: admin,user\n# after\nx-hasura-roles: [\"admin\",\"user\"]","handlingStrategy":"validation","validationCode":"// Client-side: ensure JSON-typed session variables parse\nlet v: serde_json::Value = serde_json::from_str(raw).map_err(|e| format!(\"invalid JSON: {e}\"))?;","typeGuard":null,"tryCatchPattern":"match err {\n    InternalDeveloperError::VariableExpectedJson { session_variable, parse_error } => {\n        eprintln!(\"{session_variable} must be valid JSON: {parse_error}\");\n    }\n    _ => {}\n}","preventionTips":["JSON-encode list/object session variables (arrays as [\\\"a\\\",\\\"b\\\"] )","Validate session variables in the auth webhook before forwarding"],"tags":["session-variables","json","parse-error","hasura"],"backgroundTag":"invalid-json","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}