{"record":{"id":"0dad0b6935097b48","repo":"googleapis/mcp-toolbox","slug":"failed-to-parse-data-quality-spec-json-w","errorCode":null,"errorMessage":"failed to parse data quality spec JSON: %w","messagePattern":"failed to parse data quality spec JSON: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/dataplex/dataplex.go","lineNumber":1048,"sourceCode":"\t\t\t\t\"onemcp-server\": \"true\",\n\t\t\t},\n\t\t},\n\t}\n\n\top, err := s.DataScanClient.CreateDataScan(ctx, req)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn op.Name(), nil\n}\n\nfunc (s *Source) GenerateDataQuality(ctx context.Context, location, resourcePath string, specJSON string, publish bool) (string, error) {\n\tparent := fmt.Sprintf(\"projects/%s/locations/%s\", s.ProjectID(), location)\n\tdataScanID := fmt.Sprintf(\"nq-dq-%s\", uuid.New().String())\n\n\tvar dqSpec dataplexpb.DataQualitySpec\n\tif err := protojson.Unmarshal([]byte(specJSON), &dqSpec); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to parse data quality spec JSON: %w\", err)\n\t}\n\tdqSpec.CatalogPublishingEnabled = publish\n\n\treq := &dataplexpb.CreateDataScanRequest{\n\t\tParent:     parent,\n\t\tDataScanId: dataScanID,\n\t\tDataScan: &dataplexpb.DataScan{\n\t\t\tData: &dataplexpb.DataSource{\n\t\t\t\tSource: &dataplexpb.DataSource_Resource{\n\t\t\t\t\tResource: resourcePath,\n\t\t\t\t},\n\t\t\t},\n\t\t\tSpec: &dataplexpb.DataScan_DataQualitySpec{\n\t\t\t\tDataQualitySpec: &dqSpec,\n\t\t\t},\n\t\t\tExecutionSpec: &dataplexpb.DataScan_ExecutionSpec{\n\t\t\t\tTrigger: &dataplexpb.Trigger{\n\t\t\t\t\tMode: &dataplexpb.Trigger_OneTime_{","sourceCodeStart":1030,"sourceCodeEnd":1066,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/dataplex/dataplex.go#L1030-L1066","documentation":"GenerateDataQuality accepts a caller-supplied DataQualitySpec as JSON and decodes it with protojson into a DataQualitySpec proto before creating a DataScan. If the JSON is not valid JSON or does not match the DataQualitySpec schema (wrong field names, wrong types, non-camelCase keys without protojson options), the parse fails with this wrapped error.","triggerScenarios":"Calling GenerateDataQuality with specJSON containing malformed JSON, unknown fields (protojson rejects unknown fields by default), snake_case keys instead of camelCase, or wrong value types (e.g. string where a number is required).","commonSituations":"Hand-authoring the spec with snake_case field names; copying a spec from a different proto version; trailing commas or comments in the JSON; embedding rules with invalid rowCondition expressions at the JSON type level.","solutions":["Validate specJSON with a JSON linter and against the DataQualitySpec proto schema","Use camelCase field names (protojson convention) e.g. rowCondition not row_condition","Remove unknown fields — protojson.Unmarshal rejects them by default; or parse with protojson.UnmarshalOptions{DiscardUnknown: true} in a fork/patch","Start from a minimal known-good spec (e.g. {\"rules\":[]}) and add fields incrementally"],"exampleFix":"// before\nspec := `{\"rules\": [{\"row_condition\": \"col > 0\", \"suspicious_threshold\": 0.5}]}`\n// after\nspec := `{\"rules\": [{\"rowCondition\": \"col > 0\", \"suspiciousThreshold\": 0.5}]}`","handlingStrategy":"validation","validationCode":"var probe map[string]any\nif err := json.Unmarshal([]byte(specJSON), &probe); err != nil {\n\treturn fmt.Errorf(\"invalid spec JSON: %w\", err)\n}\nif _, ok := probe[\"rules\"]; !ok { return errors.New(\"spec missing 'rules' field\") }","typeGuard":null,"tryCatchPattern":"id, err := src.GenerateDataQuality(ctx, loc, res, spec, true)\nif err != nil {\n\tif strings.Contains(err.Error(), \"failed to parse data quality spec JSON\") {\n\t\treturn fmt.Errorf(\"fix spec JSON (camelCase keys, no unknown fields): %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Use camelCase protojson field names","Validate the spec against the DataQualitySpec proto schema before submitting","Reject unknown fields in a pre-flight JSON schema check","Lint user-supplied JSON before calling the tool"],"tags":["dataplex","json","protojson","data-quality","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}