Regex for JSON Boolean
Regex Pattern
^(?:true|false)$JSON boolean literal (true or false)
Quick Answer
The regex pattern for json boolean is `^(?:true|false)$`. JSON boolean literal (true or false). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| true | ✓ Matches |
| false | ✓ Matches |
| True | ✗ No match |
| FALSE | ✗ No match |
| 1 | ✗ No match |
| yes | ✗ No match |
| null | ✗ No match |
Code Examples
javascript
const regex = /^(?:true|false)$/; const isValid = regex.test(value);
python
import re
pattern = r'^(?:true|false)$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^(?:true|false)$/ if value =~ pattern puts "valid" end
php
if (preg_match('/^(?:true|false)$/', $value)) {
echo "valid";
}java
String pattern = "^(?:true|false)$"; boolean isValid = value.matches(pattern);
Frequently Asked Questions
Related Regex Patterns
JavaScript Variable Name
Valid JavaScript variable/identifier name
Python Variable Name
Valid Python identifier name
CSS Class Name
Valid CSS class name (starts with letter, underscore, or hyphen)
CSS ID Selector
CSS ID selector starting with #
JSON Key
JSON object key (quoted string followed by colon)
Semantic Version (Strict)
Strict semantic versioning (MAJOR.MINOR.PATCH)