PHPackages                             secit-pl/json-ld-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. secit-pl/json-ld-bundle

ActiveSymfony-bundle[API Development](/categories/api)

secit-pl/json-ld-bundle
=======================

Schema.org JSON-LD generator Symfony Bundle.

2.2.1(8y ago)615.8k↓100%8MITPHPPHP &gt;=5.4.0

Since Dec 21Pushed 4y agoCompare

[ Source](https://github.com/secit-pl/json-ld-bundle)[ Packagist](https://packagist.org/packages/secit-pl/json-ld-bundle)[ Docs](http://secit.pl)[ RSS](/packages/secit-pl-json-ld-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (3)Versions (12)Used By (0)

Schema.org JSON-LD Symfony Bundle
=================================

[](#schemaorg-json-ld-symfony-bundle)

Schema.org JSON-LD generator for the Symfony 2.8 and 3.0+.

#### PHP 7 support

[](#php-7-support)

As of release 3.3.2 of the  all types and properties should be suffixed. This bundle allows using both class versions (the new suffixed classes and the deprecated non suffixed), but be aware that only suffixed classes will work properly on the PHP 7.

Another reason for moving to the new class naming schema is the fact that all non suffixed classes will be removed in the release 3.4 of the secit-pl/schema-org.

Installation
------------

[](#installation)

From the command line run

```
$ composer require secit-pl/json-ld-bundle

```

Update your AppKernel by adding the bundle declaration

```
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            ...
            new SecIT\JsonLdBundle\JsonLdBundle(),
        ];

        ...
    }
}
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

First of all you need to create a Transformer which will transform your object to schema.org data mapping.

```
namespace Test\TestBundle\JsonLd;

use SecIT\JsonLdBundle\Transformer\TransformerInterface;
use SecIT\SchemaOrg\Mapping\DataType\TextType;
use SecIT\SchemaOrg\Mapping\Property\NameProperty;
use SecIT\SchemaOrg\Mapping\Type\ThingType;

class TestTransformer implements TransformerInterface
{
    public function transform($object)
    {
        return (new ThingType())
            ->setName(new NameProperty(
                new TextType($object->getName())
            ));
    }
}
```

As the basis for this of this bundle is the  so the transformer should return the object accepted by the JSON-LD Generator.

Next you need to register the transformer as service using the secit.jsonld\_transformer tag in your services.yml.

```
services:
    test.object_transformer:
        class: Test\TestBundle\JsonLd\TestTransformer
        tags:
            - { name: secit.jsonld_transformer, class: Test\TestBundle\Classes\ClassToBeTransformedToJsonLd }
```

If you want to assign more than one class to the same transformer you can add multiple tags to the same service.

```
services:
    test.object_transformer:
        class: Test\TestBundle\JsonLd\TestTransformer
        tags:
            - { name: secit.jsonld_transformer, class: Test\TestBundle\Classes\Class1 }
            - { name: secit.jsonld_transformer, class: Test\TestBundle\Classes\Class2 }
            - { name: secit.jsonld_transformer, class: Test\TestBundle\Classes\Class3 }
            ...
```

From now you can transform the specified in the tag class attribute object (in the following example the \\Test\\TestBundle\\Classes\\ClassToBeTransformedToJsonLd) to the JSON-LD as following:

```
$object = new \Test\TestBundle\Classes\ClassToBeTransformedToJsonLd();
$object->setName('Some name');
echo $this->getContainer()->get('secit.json_ld')->generate($object);
```

The output should be something like this:

```
{"@context":"http:\/\/schema.org","@type":"Thing","name":"Some name"}
```

### Advanced usage

[](#advanced-usage)

In many situations it's required to have a nested transformers to not implement whole logic in the single class. To use nested transformers your Transformer should implement JsonLdAwareInterface. If you don't want to implement the interface methods by your own you can use the JsonLdAwareTrait.

Here is the simple example of how to use it:

PersonTransformer.php

```
namespace Test\TestBundle\JsonLd;

use SecIT\JsonLdBundle\DependencyInjection\JsonLdAwareInterface;
use SecIT\JsonLdBundle\DependencyInjection\JsonLdAwareTrait;
use SecIT\JsonLdBundle\Transformer\TransformerInterface;
use SecIT\SchemaOrg\Mapping\DataType\TextType;
use SecIT\SchemaOrg\Mapping\Property\NameProperty;
use SecIT\SchemaOrg\Mapping\Type\PersonType;

class PersonTransformer implements TransformerInterface
{
    public function transform($person)
    {
        return (new PersonType())
            ->setName(new NameProperty(
                new TextType($person->name)
            ));
    }
}
```

ArticleTransformer.php

```
namespace Test\TestBundle\JsonLd;

use SecIT\JsonLdBundle\DependencyInjection\JsonLdAwareInterface;
use SecIT\JsonLdBundle\DependencyInjection\JsonLdAwareTrait;
use SecIT\JsonLdBundle\Transformer\TransformerInterface;
use SecIT\SchemaOrg\Mapping\DataType\TextType;
use SecIT\SchemaOrg\Mapping\Property\AuthorProperty;
use SecIT\SchemaOrg\Mapping\Property\NameProperty;
use SecIT\SchemaOrg\Mapping\Type\ArticleType;

class ArticleTransformer implements TransformerInterface, JsonLdAwareInterface
{
    use JsonLdAwareTrait;

    public function transform($article)
    {
        return (new ArticleType())
            ->setName(new NameProperty(
                new TextType($article->name)
            ))
            ->setAuthor(new AuthorProperty(
                $this->getJsonLd()->transform($article->author)
            ));
    }
}
```

Example input object:

```
$author = new Person();
$author->name = 'Jon Smith';

$article = new Article();
$article->name = 'Example article';
$article->author = $author;
```

The output:

```
{"@context":"http:\/\/schema.org","@type":"Article","name":"Example article","author":{"@type":"Person","name":"Jon Smith"}}
```

### Twig Support

[](#twig-support)

This bundle also provides the Twig extension which allows to render JSON-LD directly from the Twig templates.

TestController:

```
namespace Test\TestBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class TestController extends Controller
{
    public function testAction()
    {
        return $this->render('TestBundle:Test:example.html.twig', [
            'object' => new Foo(),
        ]);
    }
}
```

example.html.twig:

```
{{ object|json_ld }}
```

The output:

```
{"@context":"http:\/\/schema.org", ... }
```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~80 days

Total

11

Last Release

3108d ago

Major Versions

1.3.2 → 2.0.02017-01-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/16771e4f1b72d12f981ed61b585a74501530faf699086fb30b26ef6117399227?d=identicon)[secit](/maintainers/secit)

---

Top Contributors

[![secit-pl](https://avatars.githubusercontent.com/u/24696884?v=4)](https://github.com/secit-pl "secit-pl (24 commits)")

---

Tags

symfonybundleschemageneratorJSON-LDstructured-dataschema.org

### Embed Badge

![Health badge](/badges/secit-pl-json-ld-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/secit-pl-json-ld-bundle/health.svg)](https://phpackages.com/packages/secit-pl-json-ld-bundle)
```

###  Alternatives

[harmbandstra/swagger-ui-bundle

Exposes swagger UI inside your Symfony project through a route (eg. /docs)

42867.3k](/packages/harmbandstra-swagger-ui-bundle)[cravler/maxmind-geoip-bundle

Bundle integrating MaxMind GeoIP2 database into symfony application

27615.8k2](/packages/cravler-maxmind-geoip-bundle)[onmoon/openapi-server-bundle

Symfony bundle to create a fully-featured API server from an OpenAPI v3 specification

1117.7k](/packages/onmoon-openapi-server-bundle)[ufo-tech/json-rpc-sdk-bundle

The Symfony bundle for simple usage Json-RPC api with dynamic SDK

172.5k](/packages/ufo-tech-json-rpc-sdk-bundle)[stfalcon-studio/api-bundle

Base classes and helper services to build API application via Symfony.

1032.1k](/packages/stfalcon-studio-api-bundle)[maxbeckers/amazon-alexa-bundle

Symfony Bundle for amazon alexa skills.

132.1k](/packages/maxbeckers-amazon-alexa-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
