json_encode online
Simulate PHP's json_encode() function online. Test JSON encoding with all options and flags. Convert PHP values to JSON and see exactly how PHP encodes your data.
json_encode(mixed $value, int $flags = 0, int $depth = 512): string|false Options & Flags
PHP Code Input
Write PHP code with $data variable (required)
JSON Output
PHP Examples
Click on any example to test json_encode():
json_encode() Function Guide
About json_encode()
This tool runs actual PHP 8.2 code on our server using Docker containers. Unlike simulators, it executes real PHP's json_encode() function, ensuring 100% accurate results that match your production environment. Write your PHP code, and see the exact JSON output that PHP generates.
- Converts PHP arrays and objects to JSON strings
- Supports multiple encoding flags for customization
- Handles Unicode characters and special escaping
- Provides pretty-printing for readable output
- Validates and encodes complex nested structures
Common Flags Explained
JSON_PRETTY_PRINT: Formats the output with whitespace and newlines for better readability. Useful for debugging and human-readable JSON files.
JSON_UNESCAPED_SLASHES: Prevents forward slashes (/) from being escaped as \\/. Commonly used for URLs and file paths.
JSON_UNESCAPED_UNICODE: Encodes Unicode characters as their literal representation instead of \uXXXX escape sequences. Great for international text.
JSON_NUMERIC_CHECK: Automatically converts numeric strings to JSON numbers instead of strings. Useful when dealing with form data or CSV imports.
Request a Feature
Have an idea to improve this tool? Share your suggestions and help us make it better! (One request per day)

