{"record":{"id":"4205d31c28ebb115","repo":"different-ai/openwork","slug":"label-syntax-enter-valid-json","errorCode":null,"errorMessage":"${label} syntax: enter valid JSON.","messagePattern":"(.+?) syntax: enter valid JSON\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/workflow-detail-panel.tsx","lineNumber":34,"sourceCode":"  useUpdateWorkflowAutomation,\n  useWorkflowDetail,\n  useWorkflowSnapshots,\n} from \"./workflow-data\";\n\ntype Fields = { name: string; description: string; code: string; input: string; inputSchema: string; outputSchema: string };\nconst AGE_OPTIONS = [{ label: \"1 hour\", value: 3_600_000 }, { label: \"1 day\", value: 86_400_000 }, { label: \"1 week\", value: 604_800_000 }];\n\nfunction pretty(value: unknown) {\n  return value === null || value === undefined ? \"\" : JSON.stringify(value, null, 2);\n}\n\nfunction initialFields(detail: WorkflowDetail): Fields {\n  return { name: detail.title, description: detail.description ?? \"\", code: detail.currentVersion.code ?? \"\", input: pretty(detail.currentVersion.exampleInput ?? {}), inputSchema: pretty(detail.currentVersion.inputSchema), outputSchema: pretty(detail.currentVersion.outputSchema) };\n}\n\nfunction parseJson(label: string, value: string, optional = false) {\n  if (!value.trim() && optional) return undefined;\n  try { return JSON.parse(value.trim() || \"null\"); } catch { throw new Error(`${label} syntax: enter valid JSON.`); }\n}\n\nfunction toDraft(detail: WorkflowDetail, fields: Fields): WorkflowDraft {\n  return {\n    name: fields.name.trim(),\n    description: fields.description.trim() || undefined,\n    code: fields.code,\n    exampleInput: parseJson(\"Example input\", fields.input),\n    inputSchema: parseJson(\"Input schema\", fields.inputSchema, true),\n    outputSchema: parseJson(\"Output schema\", fields.outputSchema, true),\n    requiredCapabilities: detail.currentVersion.requiredCapabilities,\n  };\n}\n\nfunction message(error: unknown) {\n  return error instanceof Error ? error.message : \"The Workflow action failed.\";\n}\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/workflow-detail-panel.tsx#L16-L52","documentation":"parseJson in workflow-detail-panel.tsx parses user-entered form fields (input, inputSchema, outputSchema) before building a WorkflowDraft. Empty optional fields become undefined; any JSON.parse failure throws '${label} syntax: enter valid JSON.' so the save is aborted with a per-field message.","triggerScenarios":"Submitting the workflow detail form with malformed JSON in a labeled field — e.g. trailing commas, single quotes, unquoted keys, truncated paste of input/inputSchema/outputSchema — or a required field left empty when optional=false (JSON.parse('' || 'null') yields null, which downstream schema validation may reject).","commonSituations":"Pasting a schema from a document that mangled quotes, editing JSON by hand and leaving a trailing comma, clearing a required schema field, copying JSON with smart quotes from a chat/markdown renderer, or saving before finishing an edit.","solutions":["Fix the JSON in the flagged field (validate it in a linter/JSON parser first).","Remove trailing commas, smart quotes, and unquoted keys.","If the field is optional, either leave it fully empty or supply valid JSON.","Re-check required (non-optional) fields are non-empty and parse to the expected object/array.","Paste via a plain-text editor to strip smart quotes and invisible characters."],"exampleFix":"// before\n{\"name\": \"run\", 'type': \"object\",}\n// after\n{\"name\": \"run\", \"type\": \"object\"}","handlingStrategy":"validation","validationCode":"function isValidJson(s: string): boolean {\n  if (!s.trim()) return false;\n  try { JSON.parse(s); return true; } catch { return false; }\n}\n// validate each field before submit and mark invalid fields inline","typeGuard":"null","tryCatchPattern":"try {\n  const draft = toDraft(detail, fields);\n  await save(draft);\n} catch (e) {\n  if (e instanceof Error && e.message.endsWith(\"enter valid JSON.\")) {\n    setFieldError(e.message.split(\" \")[0]); return;\n  }\n  throw e;\n}","preventionTips":["Validate JSON fields on blur with inline error markers.","Paste schemas through a plain-text editor to strip smart quotes.","Use a code editor component (JSON syntax highlighting) for schema fields.","Never submit the form while any JSON field is invalid."],"tags":["json","validation","form","user-input"],"backgroundTag":"invalid-json-syntax","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}