Skip to content

Fix JsonLd generate() to respect the $minify parameter#392

Open
RohithVangalla1 wants to merge 1 commit into
artesaos:masterfrom
RohithVangalla1:fix/jsonld-respect-minify-parameter
Open

Fix JsonLd generate() to respect the $minify parameter#392
RohithVangalla1 wants to merge 1 commit into
artesaos:masterfrom
RohithVangalla1:fix/jsonld-respect-minify-parameter

Conversation

@RohithVangalla1
Copy link
Copy Markdown

Summary

The generate() method in JsonLd and JsonLdMulti accepted a $minify parameter
but completely ignored it — JSON-LD output was always minified.

Fix

  • JsonLd::generate(): When $minify is false (default), adds JSON_PRETTY_PRINT
    flag for readable output during development
  • JsonLdMulti::generate(): Passes $minify through to individual JsonLd instances
    (was previously hardcoded without the parameter)

Before

// $minify = false, but output is still compact:
$jsonLd->generate(false);
// <script type="application/ld+json">{"@context":"https://schema.org","@type":"Organization","name":"Example"}</script>

## After
// $minify = false → pretty-printed:
$jsonLd->generate(false);
// <script type="application/ld+json">{
//     "@context": "https://schema.org",
//     "@type": "Organization",
//     "name": "Example"
// }</script>

// $minify = true → compact (unchanged):
$jsonLd->generate(true);
// <script type="application/ld+json">{"@context":"https://schema.org","@type":"Organization","name":"Example"}</script>


| Q             | A
| ------------- | ---
| Is bugfix?    | ✔️
| Fixed issues  | comma-separated list of tickets # fixed by the PR, if any

The generate() method accepted a $minify parameter but ignored it —
JSON-LD output was always minified regardless of the flag value.

This change:
- When $minify is false (default): outputs pretty-printed JSON-LD
  with JSON_PRETTY_PRINT for better readability during development
- When $minify is true: outputs compact JSON (existing behavior)
- Passes $minify through from JsonLdMulti to individual JsonLd instances

This aligns JsonLd with the behavior of other generate() methods in
the package (OpenGraph, TwitterCards) which also accept $minify.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant