ergebnis/json-normalizer
Normalize JSON documents with composable normalizers. Includes generic and vendor-specific normalizers for formatting, indentation, schema-based ordering, JSON encoding, chaining, callbacks, and controlling final newlines. Install via Composer and apply a Normalizer to produce consistent JSON output...
Install the package with composer require ergebnis/json-normalizer. Begin by using the FormatNormalizer to enforce consistent JSON formatting (indentation, encoding options, newlines) across your project — ideal for ensuring composer.json, package.json, or custom config files follow team conventions. Check the README’s usage examples for quick start patterns; the ChainNormalizer is the most common first building block for multi-step normalization pipelines.
ChainNormalizer to compose generic normalizers (e.g., JsonEncodeNormalizer → IndentNormalizer → WithFinalNewLineNormalizer) for deterministic output. Order matters: apply encoding before pretty-printing.CallableNormalizer to inject domain-specific rules (e.g., redact secrets, restructure nested arrays) while preserving the rest of the document structure.SchemaNormalizer to enforce structure and ordering (especially for composer.json) based on official JSON Schema. Combine with Pointer\Specification::equals() to exempt specific paths (e.g., custom plugins) from reordering.Vendor\Composer\ComposerJsonNormalizer as a drop-in for standardizing composer.json formatting, sorting, and validation — similar to what composer normalize does, but integrated into tooling or CI.ChainNormalizer, IndentNormalizer must run after JsonEncodeNormalizer, or indentation settings may be lost. Test your chain pipeline with varied inputs.additionalProperties. Use Pointer\Specification (e.g., Specification::never() or Specification::equals(...)) to protect dynamic keys like extra sections.JsonEncodeNormalizer defaults to JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP. Override with JsonEncodeOptions::fromInt(...) to avoid unnecessary escaping (e.g., JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE).Normalizer\Normalizer to build custom normalizers — the interface is simple (normalize(Json $json): Json), making it easy to add project-specific rules.SchemaNormalizer validates before and after normalization. In CI/performance-sensitive workflows, consider skipping validation in production by using a lighter-weight normalizer chain or caching schema resolution.How can I help you explore Laravel packages today?