PHPackages                             ajur-media/json-ld-generator - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ajur-media/json-ld-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ajur-media/json-ld-generator
============================

Extremely simple JSON-LD markup generator (AJUR Media fork)

1.0.0(1y ago)090BSD-2-ClausePHPPHP &gt;=7.4 | 8.\*

Since Jun 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ajur-media/json-ld-generator)[ Packagist](https://packagist.org/packages/ajur-media/json-ld-generator)[ RSS](/packages/ajur-media-json-ld-generator/feed)WikiDiscussions main Synced today

READMEChangelog (2)DependenciesVersions (3)Used By (0)

JSON-LD Generator
=================

[](#json-ld-generator)

Extremely simple JSON-LD generator.

AJUR Media fork, compatible with PHP7.4 &amp; PHP 8.\*

Original code:

- [JSON-LD Generator on Packagist](https://packagist.org/packages/torann/json-ld)
- [JSON-LD Generator on GitHub](https://github.com/Torann/json-ld)

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

[](#installation)

From the command line run

```
$ composer require ajur-media/json-ld-generator

```

Methods
-------

[](#methods)

**/Context.php**

- `create($context, array $data = [])`
- `getProperties()`
- `generate($flags)`

Context Types
-------------

[](#context-types)

- article
- audiobook
- beach
- blog\_posting
- book
- breadcrumb\_list
- contact\_point
- corporation
- creative\_work
- duration
- event
- geo\_coordinates
- image\_object
- invoice
- list\_item
- local\_business
- media\_object
- music\_album
- music\_group
- music\_playlist
- music\_recording
- news\_article
- offer
- order
- organization
- person
- place
- postal\_address
- price\_specification
- product
- rating
- recipe
- review
- sculpture
- search\_box
- thing
- video\_object
- web\_page
- web\_site

Examples
--------

[](#examples)

### Quick Example

[](#quick-example)

#### Business

[](#business)

```
$context = \AJUR\Toolkit\JsonLd\Context::create('local_business', [
    'name' => 'Consectetur Adipiscing',
    'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor',
    'telephone' => '555-555-5555',
    'openingHours' => 'mon,tue,fri',
    'address' => [
        'streetAddress' => '112 Apple St.',
        'addressLocality' => 'Hamden',
        'addressRegion' => 'CT',
        'postalCode' => '06514',
    ],
    'geo' => [
        'latitude' => '41.3958333',
        'longitude' => '-72.8972222',
    ],
]);

echo $context; // Will output the script tag
```

### News Article

[](#news-article)

```
$context = \JsonLd\Context::create('news_article', [
    'headline' => 'Article headline',
    'description' => 'A most wonderful article',
    'mainEntityOfPage' => [
        'url' => 'https://google.com/article',
    ],
    'image' => [
        'url' => 'https://google.com/thumbnail1.jpg',
        'height' => 800,
        'width' => 800,
    ],
    'datePublished' => '2015-02-05T08:00:00+08:00',
    'dateModified' => '2015-02-05T09:20:00+08:00',
    'author' => [
        'name' => 'John Doe',
    ],
    'publisher' => [
        'name' => 'Google',
        'logo' => [
          'url' => 'https://google.com/logo.jpg',
          'width' => 600,
          'height' => 60,
        ]
    ],
]);

echo $context; // Will output the script tag
```

Custom Context Type
-------------------

[](#custom-context-type)

The first argument for the `create($context, array $data = [])` method also accepts class names. This is helpful for custom context types.

```
