Home → JSON to RegEx Generator

JSON to RegEx Generator

Generate regular expression patterns from your JSON structure and values.

About This Tool

Generate regular expression patterns from your JSON structure and values. This tool runs entirely in your browser — no data is ever sent to a server. Free to use, no account required.

What the JSON Regex Generator Does

The regex generator creates regular expression patterns for validating JSON string fields, saving time compared to writing patterns from scratch.

Pattern Generation from Examples

Provide example valid values and the tool infers a regex pattern that matches all of them. For example, provide several phone number examples and the tool generates a pattern that validates that format.

Common JSON Field Patterns

A library of ready-made patterns covers the most common validation needs: email address, URL, ISO 8601 date, UUID, IPv4 address, credit card number, zip code, and hex color code.

Using Regex in JSON Schema

Generated patterns integrate directly into JSON Schema validation via the pattern keyword.

The pattern Keyword

Add "pattern": "your-regex-here" to any string type field in your JSON Schema. The value must match the regex (using ECMA 262 dialect) for the schema validation to pass. The pattern must match the complete string, not just a substring.

Testing Your Patterns

Always test regex patterns against both valid examples (which should match) and invalid examples (which should not) before deploying. Edge cases like empty strings, unicode characters, and boundary values often reveal pattern issues.

Frequently Asked Questions

What is a JSON regex generator?+
A JSON regex generator creates regular expression patterns suitable for validating JSON string fields. You can generate patterns by providing example valid values (the tool infers the pattern) or by selecting from a library of common patterns for formats like email addresses, URLs, ISO dates, UUIDs, and phone numbers.
How do I use a regex pattern in JSON Schema?+
Add a 'pattern' property to any string field definition in your JSON Schema. The value is a regular expression string. For example: {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$"} validates that the field contains a valid ISO date. The pattern must match the entire string value.
Can the regex generator create patterns from my example data?+
Yes. Paste a list of valid example values and the tool analyzes their structure to generate a regex pattern that matches all of them. This works best when your examples share a consistent format. Review and test the generated pattern against edge cases before using it in production.
Are JSON regex patterns the same as JavaScript regex?+
JSON Schema uses the ECMA 262 dialect of regular expressions, which is the same as JavaScript regex. This means most JavaScript regex patterns work directly in JSON Schema. The generator produces patterns compatible with both JSON Schema validators and JavaScript code.

Ready-to-Use Regex Patterns for Common JSON Fields

Copy these tested regex patterns directly into your JSON Schema pattern keyword. All patterns use ECMA 262 regex dialect, compatible with JSON Schema validators and JavaScript.

Field Type Pattern Example valid value
Email address^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$alice@example.com
UUID v4^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$550e8400-e29b-41d4-a716-446655440000
ISO 8601 date^\d{4}-\d{2}-\d{2}$2026-03-21
ISO 8601 datetime^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+\-]\d{2}:\d{2})$2026-03-21T14:30:00Z
URL (http/https)^https?:\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-@?^=%&&/~\+#])?$https://example.com/path
IPv4 address^(\d{1,3}\.){3}\d{1,3}$192.168.1.1
Hex color code^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$#FF5733
Semantic version^\d+\.\d+\.\d+$1.2.34
Slug (URL-safe)^[a-z0-9]+(?:-[a-z0-9]+)*$my-product-name
Phone (E.164)^\+[1-9]\d{1,14}$+14155552671
Credit card (basic)^\d{13,19}$4111111111111111
Base64 encoded^[A-Za-z0-9+/]+={0,2}$SGVsbG8gV29ybGQ=

Complete JSON Schema Example with Regex Validation

Here is a real-world JSON Schema that uses pattern to validate multiple fields in a user registration object. Copy and adapt it for your own API.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "User Registration",
  "type": "object",
  "required": ["email", "username", "birthDate"],
  "properties": {
    "email": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$",
      "description": "Valid email address"
    },
    "username": {
      "type": "string",
      "pattern": "^[a-z0-9_]{3,20}$",
      "description": "3-20 lowercase alphanumeric characters or underscores"
    },
    "birthDate": {
      "type": "string",
      "pattern": "^\d{4}-\d{2}-\d{2}$",
      "description": "ISO 8601 date (YYYY-MM-DD)"
    },
    "website": {
      "type": "string",
      "pattern": "^https?:\/\/.+",
      "description": "Optional URL starting with http or https"
    },
    "phoneNumber": {
      "type": "string",
      "pattern": "^\+[1-9]\d{1,14}$",
      "description": "E.164 international phone number"
    }
  }
}

Key Rules When Using pattern in JSON Schema

Explore more tools: All JSON Tools | Validator | Pretty Print | JSON Diff

Common JSON Field Regex Patterns

The table below lists ready-to-use regex patterns for the most common field types found in JSON APIs. All patterns are anchored with ^ and $ to require a full match, preventing partial matches on fields like "hello1234" satisfying a \d{4} pattern.

Field Type Regex Pattern Matches
Email^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$alice@example.com
URL^https?://[^\s/$.?#].[^\s]*$https://example.com
UUID^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$550e8400-e29b-...
ISO Date^\d{4}-\d{2}-\d{2}$2024-01-15
ISO DateTime^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}2024-01-15T10:30:00
Phone (US)^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$+1 (555) 123-4567
IPv4^(\d{1,3}\.){3}\d{1,3}$192.168.1.1
Hex color^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$#FF5733

Using Generated Regex in JSON Schema

JSON Schema's pattern keyword validates string values against a regex. Remember that JSON requires backslashes to be double-escaped: write \\d in the JSON string to represent the regex \d.

{
  "$schema": "https://json-schema.org/draft/2020-12",
  "type": "object",
  "properties": {
    "email": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
    },
    "createdAt": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}",
      "description": "ISO 8601 datetime"
    },
    "userId": {
      "type": "string",
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    }
  }
}