{"record":{"id":"c14c7f468bb99bae","repo":"phacility/phabricator","slug":"the-regular-expression-pair-s-is-not-valid-json","errorCode":null,"errorMessage":"The regular expression pair \"%s\" is not valid JSON. Enter a valid JSON array with two elements.","messagePattern":"The regular expression pair \"(.+?)\" is not valid JSON\\. Enter a valid JSON array with two elements\\.","errorType":"validation","errorClass":"HeraldInvalidConditionException","httpStatus":null,"severity":"error","filePath":"src/applications/herald/adapter/HeraldAdapter.php","lineNumber":635,"sourceCode":"    switch ($condition_type) {\n      case self::CONDITION_REGEXP:\n      case self::CONDITION_NOT_REGEXP:\n        $ok = @preg_match($condition_value, '');\n        if ($ok === false) {\n          throw new HeraldInvalidConditionException(\n            pht(\n              'The regular expression \"%s\" is not valid. Regular expressions '.\n              'must have enclosing characters (e.g. \"@/path/to/file@\", not '.\n              '\"/path/to/file\") and be syntactically correct.',\n              $condition_value));\n        }\n        break;\n      case self::CONDITION_REGEXP_PAIR:\n        $json = null;\n        try {\n          $json = phutil_json_decode($condition_value);\n        } catch (PhutilJSONParserException $ex) {\n          throw new HeraldInvalidConditionException(\n            pht(\n              'The regular expression pair \"%s\" is not valid JSON. Enter a '.\n              'valid JSON array with two elements.',\n              $condition_value));\n        }\n\n        if (count($json) != 2) {\n          throw new HeraldInvalidConditionException(\n            pht(\n              'The regular expression pair \"%s\" must have exactly two '.\n              'elements.',\n              $condition_value));\n        }\n\n        $key_regexp = array_shift($json);\n        $val_regexp = array_shift($json);\n\n        $key_ok = @preg_match($key_regexp, '');","sourceCodeStart":617,"sourceCodeEnd":653,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/herald/adapter/HeraldAdapter.php#L617-L653","documentation":"Thrown by HeraldAdapter::willSaveCondition() for the 'regular expression pair' condition type (CONDITION_REGEXP_PAIR). The condition value must be a JSON array holding two regular expressions (one for the key, one for the value, used for matching object key/value pairs); phutil_json_decode() throws PhutilJSONParserException when the string is not valid JSON, and Herald wraps that in HeraldInvalidConditionException. Any JSON syntax error — single quotes, trailing commas, unescaped quotes — produces this error.","triggerScenarios":"Saving a Herald rule with a 'regexp pair' condition whose value is not parseable JSON, e.g. ['@key@', '@val@'] (single quotes), \"@key@\", \"@val@\" without the array brackets, a trailing comma, or an unescaped quote inside a pattern. The value is decoded with phutil_json_decode() before the two regexes are extracted and validated.","commonSituations":"Users hand-write the pair in the condition box using JavaScript-ish or shell-ish quoting instead of strict JSON. Copying from a terminal where quotes got mangled, or editing a previously saved rule and deleting a bracket or comma.","solutions":["Enter the value as a strict JSON array of two strings: [\"@key-pattern@\", \"@value-pattern@\"].","Use double quotes only; single quotes are never valid JSON.","Escape any double quote inside the patterns as \\\".","Verify with a JSON linter (echo '...' | jq .) before pasting into the condition box."],"exampleFix":"// before\n['@^Differential.*@', '@^closed@']\n\n// after\n[\"@^Differential.*@\", \"@^closed@\"]","handlingStrategy":"validation","validationCode":"// Decode the pair before attempting to save the condition\ntry {\n  $json = phutil_json_decode($value);\n} catch (PhutilJSONParserException $ex) {\n  // reject the form value; never reach willSaveCondition()\n  return pht('Regexp pair must be valid JSON, e.g. [\"@a@\", \"@b@\"]');\n}","typeGuard":"function isHeraldRegexpPairString($value) {\n  if (!is_string($value)) {\n    return false;\n  }\n  try {\n    phutil_json_decode($value);\n    return true;\n  } catch (PhutilJSONParserException $ex) {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  $editor->save();\n} catch (HeraldInvalidConditionException $ex) {\n  // the message names the exact bad pair; show it next to the\n  // condition row and keep the rest of the user's input intact\n}","preventionTips":["Always author regexp pairs through a JSON-aware editor or builder, never freehand text.","Pipe the value through `echo \"$PAIR\" | jq .` (or json_decode in PHP) before pasting it into Herald.","Remember JSON requires double quotes; single quotes are the most common cause of this error."],"tags":["herald","phabricator","php","json","validation","rule-engine"],"backgroundTag":"json-parse-error","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}