{"record":{"id":"c679ea8bdf0dd19d","repo":"payloadcms/payload","slug":"jsonobject-cannot-represent-non-object-value-pr","errorCode":null,"errorMessage":"JSONObject cannot represent non-object value: ${print(ast)}","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":64,"sourceCode":"// This named export is intended for users of CommonJS. Users of ES modules\n//  should instead use the default export.\nexport const GraphQLJSON = new GraphQLScalarType({\n  name: 'JSON',\n  description:\n    'The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',\n  parseLiteral: (ast, variables) => parseLiteral('JSON', ast, variables),\n  parseValue: identity,\n  serialize: identity,\n  specifiedByURL: 'http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf',\n})\n\nexport const GraphQLJSONObject = new GraphQLScalarType({\n  name: 'JSONObject',\n  description:\n    'The `JSONObject` scalar type represents JSON objects as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',\n  parseLiteral: (ast, variables) => {\n    if (ast.kind !== Kind.OBJECT) {\n      throw new TypeError(`JSONObject cannot represent non-object value: ${print(ast)}`)\n    }\n\n    return parseObject('JSONObject', ast, variables)\n  },\n  parseValue: ensureObject,\n  serialize: ensureObject,\n  specifiedByURL: 'http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf',\n})\n","sourceCodeStart":46,"sourceCodeEnd":73,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/graphql/src/packages/graphql-type-json/index.ts#L46-L73","documentation":"Thrown by the `parseLiteral` of the `JSONObject` scalar when the AST node supplied inline is not an `OBJECT` kind. Because `JSONObject` only represents objects, an inline array, string, number, boolean, or null literal as a JSONObject argument is rejected with the printed AST. This is the literal-parsing counterpart of the `ensureObject` value check.","triggerScenarios":"Writing an inline literal that is not an object for a `JSONObject` argument: e.g. `mutation($` with `filters: [1,2]` inline, or `settings: \"default\"`. Using a variable avoids this path entirely.","commonSituations":"Inline query literals for a JSONObject field; auto-generated queries that stringify arrays; developer copying a `JSON`-style example into a `JSONObject` field.","solutions":["Provide the value as a `$variable` of type `JSONObject` so it goes through `parseValue`/`ensureObject` with a real object.","Make the inline literal an object: `{ }`.","If a non-object JSON value is valid here, change the scalar to `JSON` instead of `JSONObject`."],"exampleFix":"# before — inline array for a JSONObject argument\nmutation { update(cfg: [1, 2, 3]) { id } }\n\n# after — inline object, or use a variable\nmutation Update($cfg: JSONObject) { update(cfg: $cfg) { id } }","handlingStrategy":"validation","validationCode":"function ensureObjectForGraphQL(v) {\n  if (typeof v !== 'object' || v === null || Array.isArray(v)) {\n    throw new Error('Provide an object literal or a $variable for JSONObject')\n  }\n  return v\n}","typeGuard":"function isJSONObject(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, { cfg: ensureObjectForGraphQL(cfg) })\n} catch (e) {\n  if (e instanceof TypeError && /JSONObject cannot represent non-object value/.test(e.message)) {\n    // pass an object literal or a $variable of type JSONObject\n  }\n  throw e\n}","preventionTips":["Use a `$variable` typed `JSONObject` for non-literal values.","Never inline an array or primitive for a JSONObject argument.","If a non-object value is valid, change the scalar to `JSON`."],"tags":["graphql","json","scalar","object","parse-literal","validation"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}