RulesJson: Convert Laravel Validation Rules into Ready-to-Use JSON
Live Website: https://rules-json.msaied.com
GitHub Repository: https://github.com/EG-Mohamed/RulesJson
Introduction
RulesJson is a lightweight browser-based tool that converts Laravel validation rules into a ready-to-use JSON request body.
It is designed for Laravel developers who frequently work with APIs, FormRequest classes, validation arrays, and API testing tools such as Postman, Insomnia, Thunder Client, HTTPie, or custom frontend clients.
Instead of manually creating JSON payloads every time you write validation rules, RulesJson allows you to paste your Laravel rules and instantly generate a clean, structured, copy-ready JSON body.
The tool runs completely in the browser, uses zero dependencies, and does not send your data to any server.
What Problem Does RulesJson Solve?
When building Laravel APIs, developers usually define request validation rules first.
Example:
[
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users',
'password' => 'required|string|min:8|confirmed',
]
But when testing the endpoint, you still need to manually create a JSON request body.
Example:
{
"name": "John Doe",
"email": "user@example.com",
"password": "Password@123",
"password_confirmation": "Password@123"
}
Doing this manually is repetitive and easy to get wrong, especially when the request contains:
- Nested fields
- Dot-notation keys
- Wildcard arrays
- Confirmed fields
- Nullable values
- Enum values
- File or image fields
- Complex Laravel
FormRequestrules
RulesJson solves this by turning validation rules directly into realistic JSON payloads.
Why RulesJson Is Useful
RulesJson helps Laravel developers save time during API development and testing.
It is useful when you need to:
- Test a new Laravel API endpoint
- Generate a sample JSON body from a
FormRequest - Create API documentation examples
- Share request body samples with frontend developers
- Quickly understand the expected request structure
- Avoid mistakes in nested payloads
- Generate realistic placeholder values
- Convert Laravel validation logic into a usable JSON example
Key Features
- Converts Laravel validation rules into JSON
- Supports pipe-based validation strings
- Supports PHP associative arrays
- Supports PHP-style validation arrays
- Supports unquoted JavaScript-style objects
- Converts dot notation into nested JSON objects
- Converts wildcard fields into typed arrays
- Automatically handles
confirmedfields - Automatically selects the first value from
in:rules - Handles nullable fields intelligently
- Infers realistic values based on field names
- Supports common Laravel validation rules
- Provides syntax-highlighted JSON output
- Shows useful live statistics
- Includes a format button for cleaning input
- Supports copy to clipboard
- Includes
Ctrl + Entershortcut - Runs fully client-side
- Requires no installation for online usage
- Requires no backend server
- Has zero dependencies
Live Demo
You can use RulesJson directly from the live website:
https://rules-json.msaied.com
No account, setup, API key, or installation is required.
GitHub Repository
The source code is available on GitHub:
https://github.com/EG-Mohamed/RulesJson
How RulesJson Works
RulesJson reads Laravel validation rules from your input and converts each rule into an example JSON value.
For example:
'email' => 'required|email'
Becomes:
{
"email": "user@example.com"
}
And:
'address.city' => 'required|string'
Becomes:
{
"address": {
"city": "Cairo"
}
}
This makes it easy to turn Laravel validation structure into a practical API request body.
Supported Input Formats
RulesJson is flexible and supports multiple validation formats commonly used by Laravel developers.
1. Pipe String Rules
[
'name' => 'required|string|max:255',
'email' => 'required|email',
]
2. PHP Associative Arrays
[
'title' => 'required|string|max:255',
'price' => 'required|numeric|min:1',
]
3. PHP-Style Rule Arrays
[
'email' => ['required', 'email'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]
4. Unquoted JavaScript-Style Objects
{
name: "required|string|max:255",
email: "required|email",
is_active: "required|boolean"
}
This flexibility makes the tool useful whether your rules come from a Laravel FormRequest, controller validation, copied PHP array, or quick draft.
Rule Handling
RulesJson understands common Laravel validation rules and converts them into suitable JSON values.
Dot-Notation Nesting
Laravel often uses dot notation for nested request data.
Input:
[
'address.city' => 'required|string',
'address.country' => 'required|string',
]
Output:
{
"address": {
"city": "Cairo",
"country": "EG"
}
}
Wildcard Arrays
RulesJson supports Laravel wildcard validation rules.
Input:
[
'tags' => 'required|array',
'tags.*' => 'string|max:50',
]
Output:
{
"tags": [
"example_string"
]
}
This is helpful for array inputs such as tags, items, attachments, products, members, or permissions.
Confirmed Fields
Laravel’s confirmed rule requires a matching _confirmation field.
Input:
[
'password' => 'required|string|min:8|confirmed',
]
Output:
{
"password": "Password@123",
"password_confirmation": "Password@123"
}
RulesJson automatically creates the confirmation field for you.
Enum-Like in: Rules
For in:a,b,c rules, RulesJson selects the first valid value.
Input:
[
'role' => 'required|string|in:admin,editor,viewer',
]
Output:
{
"role": "admin"
}
Nullable Fields
RulesJson handles nullable fields intelligently.
Input:
[
'avatar' => 'nullable|image',
'bio' => 'nullable',
]
Output:
{
"avatar": null,
"bio": null
}
For binary fields such as files and images, the generated JSON value is null because binary uploads cannot be represented directly in JSON.
Integer Minimum Values
When an integer rule includes min:, RulesJson respects the minimum value.
Input:
[
'quantity' => 'required|integer|min:5',
]
Output:
{
"quantity": 5
}
Smart Field Inference
RulesJson does not generate generic values for every field.
Instead, it tries to infer better placeholder values based on the field name.
This makes the generated JSON more realistic and useful.
| Field Name Pattern | Example Output |
|---|---|
| name | John Doe |
| email | user@example.com |
| phone, mobile | +1234567890 |
| slug | example-slug |
| uuid | 550e8400-e29b-41d4-a716-446655440000 |
| birth_date, date | 2025-04-25 |
| city | Cairo |
| country | EG |
| currency | USD |
| token | eyJhbGci... |
| url, link | https://example.com |
| color | #FF2D20 |
This makes generated request bodies cleaner and easier to use in API testing.
Full Example
Input
[
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users',
'password' => 'required|string|min:8|confirmed',
'role' => 'required|string|in:admin,editor,viewer',
'is_active' => 'required|boolean',
'avatar' => 'nullable|image',
'address.city' => 'required|string',
'tags' => 'required|array',
'tags.*' => 'string|max:50',
]
Output
{
"name": "John Doe",
"email": "user@example.com",
"password": "Password@123",
"password_confirmation": "Password@123",
"role": "admin",
"is_active": true,
"avatar": null,
"address": {
"city": "Cairo"
},
"tags": [
"example_string"
]
}
Supported Rule to Output Map
| Laravel Rule | Generated JSON Output |
|---|---|
| string | Field-name-aware string |
| integer | 1 or the min: value |
| numeric | 1.0 |
| boolean | true |
| email | user@example.com |
| url | https://example.com |
| date | YYYY-MM-DD |
| uuid | UUID v4 string |
| ip | 192.168.1.1 |
| image | null |
| file | null |
| in:a,b,c | First option, such as a |
| nullable without type | null |
| confirmed | Adds field_confirmation |
| array with field.* | Single-item typed array |
| address.city | Nested object |
User Interface Features
RulesJson includes a simple developer-friendly interface.
Syntax-Highlighted JSON Output
The generated JSON is formatted and syntax-highlighted, making it easy to read and copy.
Live Stats
RulesJson shows useful stats about the generated JSON, such as:
- Root fields count
- Nested keys count
- Arrays count
- Nullable fields count
- Output size
These stats are helpful when working with large request bodies.
Format Button
The Format button helps clean and format the input in place.
This is useful when pasting messy validation arrays from a controller, request class, or documentation.
Copy to Clipboard
RulesJson includes a copy button so you can quickly copy the generated JSON into your API client.
It also includes an execCommand fallback, which improves compatibility with:
- HTTP pages
- WebViews
- Older browser environments
- Restricted clipboard contexts
Keyboard Shortcut
You can use:
Ctrl + Enter
To quickly generate the JSON output.
100% Client-Side
RulesJson runs entirely in the browser.
No validation rules, request bodies, or pasted code are sent to a server.
This is important when working with private projects, internal APIs, or sensitive field names.
Zero Dependencies
RulesJson uses:
- Vanilla JavaScript
- Tailwind CDN
There are no backend dependencies, no build process, and no required package installation.
Usage
Option A: Use the Live Website
Open:
Paste your Laravel validation rules, generate the JSON, then copy the result into your API client.
Option B: Self-Host Locally
Clone the repository:
git clone https://github.com/EG-Mohamed/RulesJson.git
cd RulesJson
Open the project:
open index.html
No build step is required.
You can also open index.html manually in your browser.
No Build Step Required
RulesJson is intentionally simple.
You do not need:
- Composer
- NPM
- Node.js
- Vite
- Laravel
- Database
- Backend server
Just open the HTML file and use the tool.
Common Use Cases
RulesJson is useful for many Laravel development workflows.
API Testing
Quickly create JSON request bodies for tools like:
- Postman
- Insomnia
- Thunder Client
- Laravel HTTP tests
- REST Client
- HTTPie
- Bruno
FormRequest Development
When creating a new Laravel FormRequest, paste the rules into RulesJson and generate a sample body instantly.
Frontend Handoff
Backend developers can share generated JSON examples with frontend developers.
This makes it easier for frontend teams to understand the expected request structure.
API Documentation
RulesJson can help generate clean example request bodies for API docs.
It is useful when documenting endpoints for:
- Internal teams
- Public APIs
- Client projects
- SaaS products
- Mobile app developers
QA Testing
QA testers can use generated JSON bodies as a starting point for manual or automated API testing.
Laravel Package Development
If you are building Laravel packages that expose API endpoints, RulesJson can help you generate sample payloads from validation rules.
Example Workflow
A typical workflow looks like this:
- Write your Laravel validation rules.
- Copy the rules array from your
FormRequest. - Open RulesJson.
- Paste the rules.
- Generate the JSON body.
- Copy the output.
- Paste it into your API client.
- Send the request and test the endpoint.
Example with Nested Data
Input:
[
'user.name' => 'required|string|max:255',
'user.email' => 'required|email',
'profile.bio' => 'nullable|string',
'profile.city' => 'required|string',
]
Output:
{
"user": {
"name": "John Doe",
"email": "user@example.com"
},
"profile": {
"bio": "example_string",
"city": "Cairo"
}
}
Example with Array Items
Input:
[
'items' => 'required|array',
'items.*.name' => 'required|string',
'items.*.quantity' => 'required|integer|min:1',
'items.*.price' => 'required|numeric|min:10',
]
Output:
{
"items": [
{
"name": "John Doe",
"quantity": 1,
"price": 10
}
]
}
Example with Confirmation
Input:
[
'password' => 'required|string|min:8|confirmed',
]
Output:
{
"password": "Password@123",
"password_confirmation": "Password@123"
}
Example with Nullable File
Input:
[
'title' => 'required|string|max:255',
'attachment' => 'nullable|file',
]
Output:
{
"title": "example_string",
"attachment": null
}
Benefits for Laravel Developers
RulesJson helps Laravel developers:
- Save time
- Avoid manual JSON writing
- Reduce request body mistakes
- Speed up endpoint testing
- Improve API documentation
- Generate realistic sample payloads
- Work faster with frontend teams
- Handle complex validation rules more easily
Benefits for Teams
RulesJson is helpful for teams because it creates a shared workflow between backend, frontend, QA, and documentation.
Backend developers can generate request examples from validation rules.
Frontend developers can use the generated JSON to understand the payload shape.
QA testers can use the JSON as test data.
Technical writers can use it in API documentation.
Privacy and Security
RulesJson runs entirely in the browser.
That means:
- No pasted validation rules are uploaded
- No request bodies are stored
- No API keys are required
- No backend processing is used
- No database is involved
- No tracking is needed for conversion logic
This makes it safe to use with private Laravel projects and internal API structures.
Limitations
RulesJson generates example JSON request bodies. It does not execute Laravel validation itself.
This means:
- It does not connect to your Laravel app
- It does not check database uniqueness
- It does not validate business logic
- It does not upload files
- It does not know custom validation rule behavior unless represented by supported patterns
For custom validation rules, RulesJson will still try to generate a sensible value based on the field name and known rule types.
Suggested Improvements
Possible future improvements could include:
- Support for more Laravel validation rules
- Export as cURL request
- Export as Postman body
- Save recent conversions locally
- Dark mode
- More field-name inference patterns
- TypeScript rewrite
- Offline PWA support
- Better handling for deeply nested wildcard arrays
- Custom placeholder settings
Contributing
Contributions are welcome.
To contribute:
- Fork the repository.
- Create a feature branch.
- Make your changes.
- Commit your changes.
- Push the branch.
- Open a pull request.
Example:
git checkout -b feature/your-feature
git commit -m "feat: describe your change"
git push origin feature/your-feature
For significant changes, it is better to open an issue first and discuss the idea.
License
RulesJson is open-source software licensed under the MIT License.
See the license file in the repository:
https://github.com/EG-Mohamed/RulesJson/blob/main/LICENSE
Author
Created by Mohamed Said.
Website:
GitHub:
Conclusion
RulesJson is a practical tool for Laravel developers who want to convert validation rules into usable JSON request bodies quickly.
It supports common Laravel validation formats, dot-notation nesting, wildcard arrays, confirmed fields, nullable values, enum values, and smart field-name inference.
Because it runs fully client-side with zero dependencies, it is simple, private, fast, and easy to self-host.
For source code, live usage, and contribution details, visit: