- What is ergebnis/json-normalizer used for in Laravel projects?
- It is a PHP package that normalizes JSON documents using composable normalizers, so you can standardize composer.json, custom config JSON, or generated JSON files in build scripts. In Laravel projects it fits best in CI/CD or local tooling rather than runtime controllers or models. It provides generic normalizers for formatting, indentation, encoding, and final newlines, plus vendor-specific and schema-aware options.
- How do I install ergebnis/json-normalizer in a Laravel application?
- Install it with Composer, usually as a dev dependency because it is a build-time tool: composer require --dev ergebnis/json-normalizer. There is no Laravel service provider or facade to register. You then call the normalizers from an Artisan command, Composer script, or CI workflow.
- Does ergebnis/json-normalizer support Laravel 8, 9, 10, and 11?
- The package requires PHP 7.4 or later, which aligns with Laravel 8 and newer, and it has no known conflicts with Laravel core components. Laravel is not explicitly listed as a dependency because the package is framework-agnostic. Confirm compatibility by running it in your project's PHP version and pipeline before upgrading major Laravel versions.
- Can I use ergebnis/json-normalizer to normalize composer.json in a CI pipeline?
- Yes, that is a strong use case because composer.json is a JSON document and the package includes formatting, indentation, and final-newline normalizers. Add it as a dev dependency and invoke a normalizer from a script or GitHub Actions step after code changes but before packaging or deployment. Keep error handling around schema failures so a normalization issue does not silently alter dependency definitions.
- How does ChainNormalizer work for combining multiple JSON normalizers?
- ChainNormalizer composes several normalizers that implement the package's Normalizer interface into one pipeline. You can combine indentation, formatting, encoding, and final-newline normalizers so a single call applies them in sequence. This is useful when you need consistent output across multiple JSON files without duplicating normalization logic.
- What does SchemaNormalizer do and can it validate Laravel config JSON?
- SchemaNormalizer is a schema-aware normalizer that uses a JSON schema to guide how a JSON document is normalized. It can surface schema validation problems, so you should test it against your custom Laravel config JSON files before relying on it in CI. Laravel's standard config files are PHP arrays, not JSON, so they would need conversion or separate handling.
- Is ergebnis/json-normalizer suitable for runtime Laravel application code?
- It is not designed for runtime application logic such as Eloquent API responses or dynamic configuration loading. Laravel already handles JSON serialization through native arrays and its own response classes. The package is most appropriate for build-time tasks, developer tooling, and CI/CD normalization of JSON files.
- How do I test JSON normalization in a Laravel project?
- Write a PHPUnit or Pest test that passes sample JSON through your chosen normalizer or ChainNormalizer and asserts the exact expected output, including indentation and final newline behavior. For CI, add a separate step that normalizes target files and fails if the output differs from the committed version. This catches regressions in composer.json or custom JSON config before deployment.
- What are the alternatives to ergebnis/json-normalizer for Laravel JSON formatting?
- You can use native json_encode with JSON_PRETTY_PRINT and custom newline handling, Composer's own normalization commands for composer.json, or general-purpose PHP code formatters. The ergebnis package is useful when you want composable normalizer classes, schema-aware normalization, and vendor-specific conventions in one interface. Evaluate it against simpler scripts if you only need basic indentation.
- What are the maintenance and production risks of using ergebnis/json-normalizer?
- The package is MIT licensed and has active CI workflows, but it has zero dependents, which means limited real-world testing and a moderate risk of edge-case issues. Support comes from its documentation and GitHub issues rather than Laravel-specific resources. Use it as a dev dependency with pinned versions, test large JSON files, and wrap normalization scripts with error handling so schema failures or unexpected reordering do not break deployments.