Skip to main content
Code & Markup · In-Browser Regular Expression Lab

JSON Key Regex — Extract All Object Keys from JSON Text

Captures all property keys from JSON formatted strings using lookahead for the colon separator.

Flags:
//g
Match Found
Load Sample:
Match Inspection & Details3 matches
Match #1:"id":
Match #2:"name":
Match #3:"active":

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

{"id": 10, "name": "Castov", "active": true} Pass

Expected Invalid Samples (Must Reject)

["value1", "value2"] Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /"([a-zA-Z_][a-zA-Z0-9_]*)"\s*:/g;
const text = "{\"id\": 10, \"name\": \"Castov\", \"active\": true}";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Matches double-quoted identifier strings followed immediately by a colon. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
"Opening quoteLiteral double quote.
([a-zA-Z_][a-zA-Z0-9_]*)Key IdentifierCaptures standard property key.
"\s*:Colon separatorTrailing quote and JSON key delimiter.

Frequently Asked Questions

Does this match values in quotes?
No, the trailing colon requirement ensures only object keys are matched.
Browse All 40 Patterns