{"record":{"id":"05e66b17e298ed87","repo":"payloadcms/payload","slug":"jsonobject-cannot-represent-non-object-value-va","errorCode":null,"errorMessage":"JSONObject cannot represent non-object value: ${value}","messagePattern":"JSONObject cannot represent non-object value: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/graphql/src/packages/graphql-type-json/index.ts","lineNumber":10,"sourceCode":"import { GraphQLScalarType } from 'graphql'\nimport { Kind, print } from 'graphql/language/index.js'\n\nfunction identity(value) {\n  return value\n}\n\nfunction ensureObject(value) {\n  if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n    throw new TypeError(`JSONObject cannot represent non-object value: ${value}`)\n  }\n\n  return value\n}\n\nfunction parseObject(typeName, ast, variables) {\n  const value = Object.create(null)\n  ast.fields.forEach((field) => {\n    value[field.name.value] = parseLiteral(typeName, field.value, variables)\n  })\n\n  return value\n}\n\nfunction parseLiteral(typeName, ast, variables) {\n  switch (ast.kind) {\n    case Kind.BOOLEAN:\n    case Kind.STRING:","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/graphql/src/packages/graphql-type-json/index.ts#L1-L28","documentation":"Thrown by the `ensureObject` helper used as `parseValue` and `serialize` for the `JSONObject` GraphQL scalar. It fires whenever the value is not a plain object — i.e. it is not `typeof 'object'`, or is `null`, or is an array. The scalar intentionally only accepts JSON objects (not arrays or primitives), unlike the more permissive `JSON` scalar. This protects the schema contract that a `JSONObject` field is always a `{ }` value.","triggerScenarios":"A GraphQL mutation/argument typed `JSONObject` receives a primitive (string/number/boolean), `null` (non-nullable), or an array in the variables. Also fires during serialization if a resolver returns an array or null for a `JSONObject` field.","commonSituations":"Confusing `JSON` (any JSON value) with `JSONObject` (object only); passing `[]` where a settings object is expected; a resolver returning `null` for a non-null JSONObject field; frontend sending `[1,2,3]` as JSON-stringified body for a field documented as an object.","solutions":["Send a plain object `{ }` instead of an array or primitive for the `JSONObject` argument.","If arbitrary JSON (arrays/primitives) is legitimately needed, switch the schema field from `GraphQLJSONObject` to `GraphQLJSON`.","Validate/coerce the value client-side: if `Array.isArray(v)` or `v === null` or `typeof v !== 'object'`, wrap or reject before sending."],"exampleFix":"// before — mutation arg typed JSONObject, value is an array\nvariables: { filters: [{ field: 'x', op: 'eq' }] }\n\n// after — wrap in an object\nvariables: { filters: { rules: [{ field: 'x', op: 'eq' }] } }","handlingStrategy":"type-guard","validationCode":"function ensurePlainObject(v) {\n  if (typeof v !== 'object' || v === null || Array.isArray(v)) {\n    throw new Error('JSONObject argument must be a plain object')\n  }\n  return v\n}","typeGuard":"function isPlainObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v)\n}","tryCatchPattern":"try {\n  await client.request(mutation, { input: ensurePlainObject(value) })\n} catch (e) {\n  if (e instanceof TypeError && /JSONObject cannot represent non-object/.test(e.message)) {\n    // wrap arrays/primitives in an object or use the JSON scalar\n  }\n  throw e\n}","preventionTips":["Prefer sending JSON scalars via `$variables` rather than inline literals.","Validate with `isPlainObject` before the request.","Choose `JSON` over `JSONObject` when arrays/primitives are valid values."],"tags":["graphql","json","scalar","validation","schema"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}