Download the PHP package qoliber/djson without Composer
On this page you can find all versions of the php package qoliber/djson. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download qoliber/djson
More information about qoliber/djson
Files in qoliber/djson
Package djson
Short Description Dynamic JSON templating library with loops, conditions, and variables
License MIT
Informations about the package djson
DJson - Dynamic JSON Templating Library
A powerful yet lightweight PHP library for creating dynamic JSON with loops, conditionals, functions, variables, and pattern matching. Think of it as a feature-rich templating engine specifically designed for JSON generation.
🚀 Features
- Variable Interpolation: Use
{{variable}}syntax with dot notation for nested access - Template Functions: 30+ built-in functions (upper, lower, date, round, join, etc.)
- Arithmetic Operations: Perform calculations with
@setdirective - Loops: Iterate over arrays with
@djson fordirective - Conditionals: Include/exclude content with
@djson if,@djson unless,@djson exists - Pattern Matching: Switch/case logic with
@djson matchand@djson switch - Variable Assignment: Set and calculate values with
@djson set - Else Statements: Full conditional logic with
@djson else - Loop Helpers: Access
_index,_key,_first,_lastin loops - Type Preservation: Maintains data types (numbers, booleans, null)
- Error Handling: Comprehensive validation with detailed error messages
- Security First: Mandatory protection against dangerous functions (eval, exec, shell_exec, etc.)
- PHP 8.1+: Modern PHP with constructor property promotion
📚 Full Documentation: https://djson.dev
Installation
Quick Start
Security
DJson takes security seriously with mandatory protection against dangerous function registration.
What's Protected
Protected Patterns
- Code Execution:
eval,assert,call_user_func - System Commands:
exec,shell_exec,system,passthru,popen,proc_open - Filesystem:
file_get_contents,file_put_contents,unlink,chmod,rename - Includes:
include,require,include_once,require_once - Serialization:
unserialize - Reflection:
reflection - Database Functions:
mysqli,mysql_,pg_,sqlite,pdo,odbc_,sqlsrv_,oci_
Safe Functions Work Fine
Why No Bypass?
Security is mandatory, not optional. If you need to execute system commands or access files, do it outside the template system where you have proper access controls. Templates are for rendering data, not executing code.
Deep Code Inspection
DJson uses PHP Reflection to inspect the actual source code of registered callables, not just function names:
This means you cannot bypass security by wrapping dangerous functions inside safe-looking closures. DJson analyzes the actual implementation and blocks any dangerous code patterns.
Core Features
Variable Interpolation with Functions
Loops with Special Variables
Conditionals with Else
Pattern Matching (Switch/Case)
Arithmetic Operations
Conditional Expressions
Built-in Template Functions
String Functions
upper,lower,capitalize,titletrim,escape,slugsubstr,replace
Number Functions
number_format,round,ceil,floor,abs
Array Functions
count,first,last,join,sort,unique
Date Functions
date,strtotime
Utility Functions
default,coalescejson_encode
See full function documentation at djson.dev/functions
Advanced Examples
E-commerce Product with Calculations
Complex Conditional Logic
For more examples, visit djson.dev/examples
Testing
DJson has comprehensive test coverage with 100% mutation score:
Test Results:
- ✅ 103 tests, 385 assertions
- 🏆 100% mutation score (70/70 meaningful mutations killed)
- ⚡ Rock-solid quality assurance
API Reference
Core Methods
Directives
| Directive | Description | Example |
|---|---|---|
@djson for <array> as <var> |
Loop over array | @djson for users as user |
@djson if <condition> |
Include if truthy | @djson if isActive |
@djson unless <condition> |
Include if falsy | @djson unless isDeleted |
@djson exists <path> |
Include if path exists | @djson exists user.email |
@djson else |
Else clause | @djson else |
@djson match <value> |
Pattern matching | @djson match status |
@djson case <pattern> |
Match case | @djson case active |
@djson default |
Default case | @djson default |
@djson set <var> = <expr> |
Set variable | @djson set total = price * qty |
{{variable}} |
Variable interpolation | {{user.name}} |
{{var \| function}} |
Apply function | {{name \| upper}} |
Loop Variables
{{_index}}- Current loop index (0-based){{_key}}- Current loop key{{_first}}-trueif first iteration{{_last}}-trueif last iteration
Requirements
- PHP 8.1 or higher
Documentation
Complete documentation available at djson.dev:
License
MIT
Author
Qoliber - [email protected]
Made with ❤️ by Qoliber | Documentation | GitHub