{"record":{"id":"8057c5ee03b8b3b0","repo":"siyuan-note/siyuan","slug":"invalid-json-s","errorCode":null,"errorMessage":"invalid JSON: %s","messagePattern":"invalid JSON: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/database.go","lineNumber":327,"sourceCode":"\t\tfmt.Println(\"ok\")\n\t\treturn nil\n\t},\n}\n\nvar databaseItemUpdateCmd = &cobra.Command{\n\tUse:   \"update --av <avID> --key <keyID> --item <itemID> --value <json>\",\n\tShort: \"Update a cell value\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tavID, _ := cmd.Flags().GetString(\"av\")\n\t\tkeyID, _ := cmd.Flags().GetString(\"key\")\n\t\titemID, _ := cmd.Flags().GetString(\"item\")\n\t\tvalueStr, _ := cmd.Flags().GetString(\"value\")\n\t\tif avID == \"\" || keyID == \"\" || itemID == \"\" || valueStr == \"\" {\n\t\t\treturn fmt.Errorf(\"--av, --key, --item and --value are required\")\n\t\t}\n\t\tvar valueData map[string]any\n\t\tif err := json.Unmarshal([]byte(valueStr), &valueData); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid JSON: %s\", err)\n\t\t}\n\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would update cell in database %s: key=%s item=%s\\n\", avID, keyID, itemID)\n\t\t\treturn nil\n\t\t}\n\n\t\tif _, err := model.UpdateAttributeViewCell(nil, avID, keyID, itemID, valueData); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tmodel.AppendPushReloadAttrViewEntry(avID)\n\t\tfmt.Println(\"ok\")\n\t\treturn nil\n\t},\n}\n\nfunc printUnusedItems(items []*model.UnusedItem) {\n\tif len(items) == 0 {","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/database.go#L309-L345","documentation":"After flag presence validation, `siyuan database item update` unmarshals the `--value` flag into a map[string]any via encoding/json. If the string is not valid JSON, or valid JSON that is not an object, json.Unmarshal errors and RunE wraps it as `invalid JSON: <detail>`. The cell value model expects a JSON object (e.g. {\"type\":\"text\",\"text\":\"...\"}).","triggerScenarios":"Passing `--value` with plain text (e.g. `--value hello`), a JSON array or scalar (e.g. `[1,2]` or `\"x\"`), truncated JSON, or unquoted special characters that the shell mangled (quotes stripped, $ expanded, newlines).","commonSituations":"Shell quoting issues stripping double quotes from the JSON; writing `--value {type:text}` without quotes; passing a value captured from logs with a trailing message; using single quotes in cmd.exe/PowerShell where they do not preserve the string.","solutions":["Quote the JSON properly for your shell and pass a JSON object: `--value '{\"type\":\"text\",\"text\":\"done\"}'`","Validate the JSON with a parser (e.g. `echo \"$VALUE\" | python -m json.tool`) before invoking the command","On Windows cmd, escape inner double quotes or write the command in a script file to avoid quoting loss","Confirm the payload is a JSON object (map), not an array or scalar, since it unmarshals into map[string]any"],"exampleFix":"// before\nsiyuan database item update --av $AV_ID --key $KEY_ID --item $ROW_ID --value done\n// after\nsiyuan database item update --av $AV_ID --key $KEY_ID --item $ROW_ID --value '{\"type\":\"text\",\"text\":\"done\"}'","handlingStrategy":"validation","validationCode":"VALUE='{\"type\":\"text\",\"text\":\"done\"}'\necho \"$VALUE\" | python3 -m json.tool > /dev/null || { echo \"invalid JSON value\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always single-quote JSON on POSIX shells and use a file or proper escaping on Windows","Store complex values in a file and use command substitution only after validating","Remember the payload must be a JSON object, not an array or bare string"],"tags":["cli","json","validation","database"],"backgroundTag":"json-parse-error","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}