{"record":{"id":"81b3d6c0ef046e40","repo":"cypress-io/cypress","slug":"params-was-not-valid-json-from-query-params","errorCode":null,"errorMessage":"params was not valid JSON: ${from.query.params}","messagePattern":"params was not valid JSON: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/app/src/router/router.ts","lineNumber":55,"sourceCode":"  routes.push({\n    path: '/redirect',\n    redirect: (from) => {\n      if (from.query.name) {\n        if (typeof from.query.name !== 'string') {\n          throw new Error(`name should be a single string but got: ${from.query.name}`)\n        }\n\n        let params = {}\n\n        if (from.query.params) {\n          if (typeof from.query.params !== 'string') {\n            throw new Error(`params should be a string but got: ${from.query.params}`)\n          }\n\n          try {\n            params = JSON.parse(from.query.params)\n          } catch {\n            throw new Error(`params was not valid JSON: ${from.query.params}`)\n          }\n        }\n\n        return {\n          name: from.query.name,\n          params,\n          query: {}, //reset query params so they do not get passed on\n        }\n      }\n\n      return { path: '/' }\n    },\n  })\n\n  const router = _createRouter({\n    history: createWebHashHistory(),\n    routes,\n  })","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/cypress-io/cypress/blob/0d85fdc91230885bca0a91df278312800a48b727/packages/app/src/router/router.ts#L37-L73","documentation":"Thrown by the /redirect route handler inside a try/catch around JSON.parse(from.query.params). The earlier guards ensured params is a string; this error fires when that string is not valid JSON (e.g. '[object Object]', a truncated payload, or hand-typed garbage). The thrown message echoes the offending value for diagnosis.","triggerScenarios":"A caller stringifies params incorrectly (Object.prototype.toString), URL-encoding mangles the JSON mid-flight, a proxy truncates the query string, or someone hand-edits the URL with non-JSON content.","commonSituations":"URLSearchParams.set with a non-stringified object, server-side middleware that rewrites query strings, or copy-paste errors when manually constructing redirect URLs.","solutions":["Always JSON.stringify the params payload before adding it to the URL.","URL-encode the JSON via URLSearchParams (it will encode for you) so proxies do not break braces.","If the value is empty, omit the params key entirely — the handler treats absence as `params = {}`.","Validate in the caller with JSON.parse before navigating."],"exampleFix":"// before\nconst url = `/redirect?name=Debug&params=${obj}` // obj.toString() = '[object Object]'\n// after\nconst params = new URLSearchParams({\n  name: 'Debug',\n  params: JSON.stringify({ from: 'notification' }),\n})\nconst url = `/redirect?${params.toString()}`","handlingStrategy":"validation","validationCode":"function parseRedirectParams (raw: string | undefined): Record<string, unknown> {\n  if (!raw) return {}\n  try { return JSON.parse(raw) }\n  catch { throw new Error(`params is not valid JSON: ${raw}`) }\n}\n\nconst params = parseRedirectParams(typeof from.query.params === 'string' ? from.query.params : undefined)","typeGuard":"function isJsonString (v: string): boolean {\n  try { JSON.parse(v); return true } catch { return false }\n}","tryCatchPattern":"try {\n  params = JSON.parse(rawParams)\n} catch (e) {\n  // log and degrade gracefully instead of throwing\n  console.warn('Ignoring invalid redirect params:', rawParams)\n  params = {}\n}","preventionTips":["Always JSON.stringify params payloads before URL insertion.","URL-encode via URLSearchParams so proxies do not mangle JSON.","Validate JSON in the caller before navigating."],"tags":["router","json-parsing","query-validation","internal","app"],"backgroundTag":null,"analyzedSha":"0d85fdc91230885bca0a91df278312800a48b727","analyzedAt":"2026-08-12T16:24:28.056Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}