PHPackages                             torann/json-ld - 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. torann/json-ld

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

torann/json-ld
==============

Extremely simple JSON-LD markup generator.

0.0.19(6y ago)149620.7k↓15.4%60[11 issues](https://github.com/Torann/json-ld/issues)[3 PRs](https://github.com/Torann/json-ld/pulls)1BSD-2-ClausePHPPHP &gt;=5.5CI failing

Since Jan 8Pushed 4y ago18 watchersCompare

[ Source](https://github.com/Torann/json-ld)[ Packagist](https://packagist.org/packages/torann/json-ld)[ RSS](/packages/torann-json-ld/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (23)Used By (1)

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

[](#json-ld-generator)

[![Build Status](https://camo.githubusercontent.com/b8245c54fceb305c8ae6f1d5ba4220d2b117fa054e17827887747472f7d91730/68747470733a2f2f7472617669732d63692e6f72672f546f72616e6e2f6a736f6e2d6c642e737667)](https://travis-ci.org/Torann/json-ld)[![Latest Stable Version](https://camo.githubusercontent.com/43ad80e8114864dbf874bd7c884f871328ca460d981a66c1d95f31f80618e76a/68747470733a2f2f706f7365722e707567782e6f72672f746f72616e6e2f6a736f6e2d6c642f762f737461626c652e706e67)](https://packagist.org/packages/torann/json-ld)[![Total Downloads](https://camo.githubusercontent.com/e322db9957dcd4dd180f17b8d70926605667092fc660295f0f2886f6ecb678cc/68747470733a2f2f706f7365722e707567782e6f72672f746f72616e6e2f6a736f6e2d6c642f646f776e6c6f6164732e706e67)](https://packagist.org/packages/torann/json-ld)[![Patreon donate button](https://camo.githubusercontent.com/f9e075baad95563481d35174d43ef50757281abb6bc795d0f473fad452afa030/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617472656f6e2d646f6e6174652d79656c6c6f772e737667)](https://www.patreon.com/torann)[![Donate weekly to this project using Gratipay](https://camo.githubusercontent.com/0eeae019980adaa1dc64842cfb01f3d738c688982ea4eb58094047011cb46704/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f67726174697061792d646f6e6174652d79656c6c6f772e737667)](https://liberapay.com/Torann/)[![Donate to this project using Flattr](https://camo.githubusercontent.com/d79e412f78041f87e203449041ad81848a8405cf0f3c622c51e3bad0c2a4b599/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f666c617474722d646f6e6174652d79656c6c6f772e737667)](https://flattr.com/profile/torann)[![Donate to this project using Paypal](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4CJA2A97NPYVU)

Extremely simple JSON-LD generator.

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

[](#installation)

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

From the command line run

```
$ composer require torann/json-ld

```

Methods
-------

[](#methods)

**/JsonLd/Context.php**

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

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 = \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
```

### Using the JSON-LD in a Laracasts Presenter

[](#using-the-json-ld-in-a-laracasts-presenter)

Even though this example shows using the JSON-LD inside of a `Laracasts\Presenter` presenter, Laravel is not required for this package.

#### /App/Presenters/BusinessPresenter.php

[](#apppresentersbusinesspresenterphp)

```
