Skip to main content
Regexflux

JSON Key-Value Pair

intermediate

Matches key-value pairs in JSON format.

jsonparsingdatakey-value

Pattern

/"([^"\\]*(?:\\.[^"\\]*)*)"\s*:\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|-?\d+(?:\.\d+)?|true|false|null)/g

Try It

0 of 7 strings matched

Explanation

Matches a JSON key (double-quoted string with escape handling) followed by colon and a value (string, number, boolean, or null).

Test Strings

Matching

  • "name": "John"
  • "age": 30
  • "active": true
  • "data": null

Non-matching

  • name: John
  • 'key': 'value'
  • {"a": [1]}

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /"([^"\\]*(?:\\.[^"\\]*)*)"\s*:\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|-?\d+(?:\.\d+)?|true|false|null)/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns