{"record":{"id":"b8d8503529989f8e","repo":"SigNoz/signoz","slug":"couldn-t-json-decode-existingfilter-w","errorCode":null,"errorMessage":"couldn't JSON decode existingFilter: %w","messagePattern":"couldn't JSON decode existingFilter: %w","errorType":"http","errorClass":"model.ApiError","httpStatus":400,"severity":"error","filePath":"pkg/query-service/app/parser.go","lineNumber":570,"sourceCode":"\t\tbaseconstants.DefaultFilterSuggestionsExamplesLimit,\n\t\tbaseconstants.MaxFilterSuggestionsExamplesLimit,\n\t)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar existingFilter *v3.FilterSet\n\texistingFilterB64 := r.URL.Query().Get(\"existingFilter\")\n\tif len(existingFilterB64) > 0 {\n\t\tdecodedFilterJson, err := base64.RawURLEncoding.DecodeString(existingFilterB64)\n\t\tif err != nil {\n\t\t\treturn nil, model.BadRequest(fmt.Errorf(\"couldn't base64 decode existingFilter: %w\", err))\n\t\t}\n\n\t\texistingFilter = &v3.FilterSet{}\n\t\terr = json.Unmarshal(decodedFilterJson, existingFilter)\n\t\tif err != nil {\n\t\t\treturn nil, model.BadRequest(fmt.Errorf(\"couldn't JSON decode existingFilter: %w\", err))\n\t\t}\n\t}\n\n\tsearchText := r.URL.Query().Get(\"searchText\")\n\n\treturn &v3.QBFilterSuggestionsRequest{\n\t\tDataSource:      dataSource,\n\t\tSearchText:      searchText,\n\t\tExistingFilter:  existingFilter,\n\t\tAttributesLimit: attributesLimit,\n\t\tExamplesLimit:   examplesLimit,\n\t}, nil\n}\n\nfunc parseFilterAttributeKeyRequest(r *http.Request) (*v3.FilterAttributeKeyRequest, error) {\n\tvar req v3.FilterAttributeKeyRequest\n\n\tdataSource := v3.DataSource(r.URL.Query().Get(\"dataSource\"))","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/parser.go#L552-L588","documentation":"After successfully base64-decoding 'existingFilter', the bytes must be valid JSON matching v3.FilterSet. This error means decoding succeeded but json.Unmarshal failed.","triggerScenarios":"existingFilter decodes to non-JSON bytes, or JSON with wrong types (e.g. items as a string instead of array, operator misspelled structure).","commonSituations":"Encoding a partial/mocked object; schema drift between the client's FilterSet shape and the server's v3.FilterSet; double-encoding so the outer decode yields base64 text.","solutions":["Validate the JSON locally against the FilterSet schema (operator string, items array of filter items) before encoding","Print the decoded bytes and run them through a JSON validator","Ensure you encoded the final JSON once, not twice"],"exampleFix":"// before\nenc := base64.RawURLEncoding.EncodeToString([]byte(`{\"items\": \"foo\"}`))\n// after\nenc := base64.RawURLEncoding.EncodeToString([]byte(`{\"operator\":\"AND\",\"items\":[]}`))","handlingStrategy":"try-catch","validationCode":"decoded, _ := base64.RawURLEncoding.DecodeString(b64)\nvar fs v3.FilterSet\nif err := json.Unmarshal(decoded, &fs); err != nil { return fmt.Errorf(\"existingFilter is not valid FilterSet JSON\") }","typeGuard":"func isValidFilterSetJSON(b []byte) bool { var fs v3.FilterSet; return json.Unmarshal(b, &fs) == nil }","tryCatchPattern":"Catch the 400 response, decode the message, and surface which stage (base64 vs JSON) failed to the user for correction.","preventionTips":["Validate FilterSet shape before encoding","Keep client FilterSet types generated from the server schema"],"tags":["signoz","query-builder","json-decode","bad-request"],"backgroundTag":"json-deserialization-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}