{"record":{"id":"3ec9d7c149d5f4d3","repo":"apache/superset","slug":"json-not-valid-3ec9d7","errorCode":null,"errorMessage":"JSON not valid","messagePattern":"JSON not valid","errorType":"validation","errorClass":"ValidationError","httpStatus":422,"severity":"error","filePath":"superset/dashboards/schemas.py","lineNumber":116,"sourceCode":"            \"description\": \"Gets a list of dashboards, use Rison or JSON query \"\n            \"parameters for filtering, sorting, pagination and \"\n            \" for selecting specific columns and metadata.\",\n        }\n    },\n    \"info\": {\"get\": {\"summary\": \"Get metadata information about this API resource\"}},\n    \"related\": {\n        \"get\": {\n            \"description\": \"Get a list of all possible related entities for a dashboard\"\n        }\n    },\n}\n\n\ndef validate_json(value: Union[bytes, bytearray, str]) -> None:\n    try:\n        json.validate_json(value)\n    except json.JSONDecodeError as ex:\n        raise ValidationError(\"JSON not valid\") from ex\n\n\ndef validate_json_metadata(value: Union[bytes, bytearray, str]) -> None:\n    if not value:\n        return\n    try:\n        value_obj = json.loads(value)\n    except json.JSONDecodeError as ex:\n        raise ValidationError(\"JSON not valid\") from ex\n    errors = DashboardJSONMetadataSchema().validate(value_obj, partial=False)\n    if errors:\n        raise ValidationError(errors)\n\n\n# Patterns for CSS constructs that can be abused to execute scripts or pull in\n# remote stylesheets/resources. The custom CSS is stored verbatim and re-served\n# into the dashboard page, so these are rejected at validation time. Ordinary\n# styling (including ``url(...)`` referencing relative paths or ``data:`` image","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/dashboards/schemas.py#L98-L134","documentation":"Marshmallow field-level validator in the dashboard schemas: it parses the incoming value with json.validate_json and raises ValidationError('JSON not valid') when the bytes/string are not parseable JSON. It guards dashboard fields that are stored as raw JSON strings (e.g. the dashboard JSON parameter on PUT/POST).","triggerScenarios":"POST/PUT /api/v1/dashboard/ with a json_-style field containing malformed JSON — unbalanced braces, single quotes, trailing commas, or binary garbage; also triggered when a client sends a JSON-encoded string with encoding errors.","commonSituations":"Hand-building the request body and stringifying twice or not at all; copy-pasting JSON with smart quotes from a doc; charset mismatch (UTF-16 output pasted as UTF-8).","solutions":["Validate the string client-side with JSON.parse / json.loads before sending.","Send the field as a real JSON object in the request body where the API accepts it, rather than a pre-stringified string.","Check for smart quotes, trailing commas, unescaped newlines, or a BOM at the start of the value.","Reproduce: python -c \"import json; json.loads(open('payload.txt').read())\" to see the exact offset of the syntax error."],"exampleFix":"// before\nbody = {\"json\": JSON.stringify(css) + \"}\"};  // broken\n\n// after\nbody = {\"json\": JSON.stringify(css)};  // valid JSON string","handlingStrategy":"validation","validationCode":"function assertValidJsonString(s: string): void {\n  try { JSON.parse(s); } catch (e) { throw new Error(`field is not valid JSON: ${e.message}`); }\n}","typeGuard":"function isJsonString(s: string): boolean {\n  try { JSON.parse(s); return true; } catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["JSON.parse every stringified field before including it in the request.","Send objects natively where the API allows instead of pre-stringified strings.","Beware BOMs and smart quotes when copying JSON from documents."],"tags":["json","validation","dashboard","marshmallow"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}