{"record":{"id":"cf38061cdd944706","repo":"larksuite/cli","slug":"invalid-json-w","errorCode":null,"errorMessage":"invalid JSON: %w","messagePattern":"invalid JSON: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_binder.go","lineNumber":175,"sourceCode":"}\n\nfunc decodeCompiledValue(raw any, field compiledInputField) (any, error) {\n\tif field.cli.Encoding == typedEncodingJSON {\n\t\ttext, ok := raw.(string)\n\t\tif !ok {\n\t\t\tencoded, err := json.Marshal(raw)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\ttext = string(encoded)\n\t\t}\n\t\tvalue := reflect.New(field.valueType)\n\t\tdecoder := json.NewDecoder(strings.NewReader(text))\n\t\tif objectShape, ok := shapeAsObject(field.shape); ok && !objectShape.AdditionalProperties {\n\t\t\tdecoder.DisallowUnknownFields()\n\t\t}\n\t\tif err := decoder.Decode(value.Interface()); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid JSON: %w\", err)\n\t\t}\n\t\tvar trailing any\n\t\tif err := decoder.Decode(&trailing); err != io.EOF {\n\t\t\tif err == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid JSON: multiple values\")\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"invalid JSON trailing content: %w\", err)\n\t\t}\n\t\treturn value.Elem().Interface(), nil\n\t}\n\treturn convertReflectValue(raw, field.valueType)\n}\n\nfunc convertReflectValue(raw any, target reflect.Type) (any, error) {\n\tif raw == nil {\n\t\treturn nil, nil\n\t}\n\trawValue := reflect.ValueOf(raw)","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_binder.go#L157-L193","documentation":"decodeCompiledValue parses a JSON-typed input field with encoding/json; when the text is not parseable as the field's target type, it wraps the decoder error as 'invalid JSON: %w'. Unknown object fields are also rejected when the field's schema disallows additionalProperties.","triggerScenarios":"Passing malformed JSON to a JSON-encoded input flag, e.g. --data '{a:1}' (unquoted keys), trailing commas, single quotes, or a type mismatch like a string where the target struct expects a number; unknown fields when the schema has AdditionalProperties=false.","commonSituations":"Shell quoting mangling double quotes; hand-written JSON with JS-style syntax; schema drift after the API added/renamed fields the user still sends.","solutions":["Validate the JSON with a parser (echo '<json>' | jq .) before passing it","Use --flag='{\"key\":\"value\"}' with proper double quotes and escape shell metacharacters","Match the target type exactly (numbers unquoted, strings quoted) and remove unknown fields","Use @file or stdin JSON input if the shell quoting is too complex"],"exampleFix":"// before\n--data \"{'name':'x'}\"\n// after\n--data '{\"name\":\"x\"}'","handlingStrategy":"validation","validationCode":"const fs = require('fs'); JSON.parse(fs.readFileSync('data.json','utf8')) // or: echo \"$DATA\" | jq -e . >/dev/null && lark-cli ... --data \"$DATA\"","typeGuard":"func isJSONObject(s string) bool { return json.Valid([]byte(s)) && strings.HasPrefix(strings.TrimSpace(s), \"{\") }","tryCatchPattern":"if err != nil && strings.HasPrefix(err.Error(), \"invalid JSON\") { log.Fatalf(\"bad --data value: %v\", err) }","preventionTips":["Validate JSON with jq or a linter before passing it","Prefer @file or stdin input for complex JSON","Double-quote flag values and escape for your shell","Match the schema's field names and types exactly"],"tags":["json","input-parsing","flag-value"],"backgroundTag":"invalid-json-input","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}