laktak/hjson
PHP library for parsing and generating Hjson (Human JSON). Read relaxed JSON with comments, optional commas, and unquoted keys/strings; stringify back to Hjson. Supports preserving whitespace/comments for round-trip editing. Install via Composer: laktak/hjson.
config/hjson) replace JSON/YAML. Reduces boilerplate (e.g., no quotes for strings/keys) while preserving JSON compatibility.HJSONParser’s dual-mode parsing.database.hjson), improving maintainability for non-technical stakeholders.? for null, and flexible whitespace—useful for generated configs (e.g., from CLI tools).config/array.php or config/json.php files with .hjson equivalents. Leverages Laravel’s Config facade or config() helper unchanged..hjson files during bootstrapping (e.g., config/hjson/mail.hjson → loaded via mergeConfigFrom).Validator if configs are parsed into arrays first (e.g., HJSONParser::parse(file_get_contents($path))).spatie/laravel-array-to-xml for strictness).hjson-js); benchmark against Symfony\Component\Yaml for large configs.jsonlint for validation or generate JSON schemas from HJSON.? syntax for null may conflict with Laravel’s null conventions (e.g., null vs. ?). Clarify: Document team-wide adoption of ? or enforce via validation.config/hjson/*.hjson)?Validator or spatie/laravel-validation-rules?phpstan, psalm) that need HJSON-aware rules?config/array.php or config/json.php with .hjson files in config/hjson/. Use Laravel’s Config facade as-is:
// config/app.hjson → parsed to array
'timezone' => 'UTC'
.hjson in .env files via str_getcsv() + HJSONParser (e.g., for multi-line configs).HJSONStringifier for user-facing configs (e.g., /api/config endpoint) if client-side HJSON support exists..hjson for CLI configs (e.g., php artisan my:command --config=path/to/config.hjson).config/hjson/mail.hjson).find config -name "*.json" -exec sh -c 'mv "$0" "${0%.json}.hjson"' {} \;
.hjson files (e.g., via composer test with a custom rule).spatie/laravel-activitylog) may need wrappers to stringify HJSON.settings column), ensure HJSONStringifier outputs valid JSON for storage.json_encode() for outbound requests.composer require laktak/hjson.config/hjson.php loader in AppServiceProvider:
public function boot()
{
$parser = new HJSONParser();
$this->mergeConfigFrom(
$parser->parse(file_get_contents(__DIR__.'/hjson/app.hjson')),
'app'
);
}
json_decode(file_get_contents(...), true) with HJSONParser::parse()..hjson syntax rules to the team’s style guide.hjson-cli).?) may be less familiar than JSON/YAML.HJSONParser in a try-catch with user-friendly output).hjson-js.config('cache')) if configs are static.| Scenario | Impact | Mitigation |
|---|---|---|
| Malformed HJSON | App crashes or loads invalid config | Fallback to JSON parsing or fail fast. |
Missing .hjson file |
Config not loaded | Use file_exists() checks or defaults. |
| Syntax changes in HJSON | Breaks existing configs | Version configs (e.g., config.v1.hjson). |
| Tooling incompatibility | CI/CD pipeline failures | Add pre-commit hooks for validation. |
?, comments, optional commas)..hjson examples to Laravel’s config/ directory.CONTRIBUTING.md snippet for HJSON config rules.HJSONParser::parse() errors.? for null if confusing).How can I help you explore Laravel packages today?