{"id":18310311,"url":"https://github.com/torann/json-ld","last_synced_at":"2025-04-04T10:07:30.419Z","repository":{"id":45557938,"uuid":"49286382","full_name":"Torann/json-ld","owner":"Torann","description":"Extremely simple JSON-LD generator.","archived":false,"fork":false,"pushed_at":"2021-12-08T21:47:53.000Z","size":139,"stargazers_count":147,"open_issues_count":17,"forks_count":60,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-04T09:56:09.186Z","etag":null,"topics":["article","json-ld","news-articles","people"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Torann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-08T17:30:15.000Z","updated_at":"2025-03-24T12:03:52.000Z","dependencies_parsed_at":"2022-09-01T04:41:26.753Z","dependency_job_id":null,"html_url":"https://github.com/Torann/json-ld","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torann%2Fjson-ld","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torann%2Fjson-ld/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torann%2Fjson-ld/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torann%2Fjson-ld/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Torann","download_url":"https://codeload.github.com/Torann/json-ld/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157281,"owners_count":20893220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["article","json-ld","news-articles","people"],"created_at":"2024-11-05T16:14:01.750Z","updated_at":"2025-04-04T10:07:30.391Z","avatar_url":"https://github.com/Torann.png","language":"PHP","funding_links":["https://www.patreon.com/torann","https://liberapay.com/Torann/","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=4CJA2A97NPYVU"],"categories":[],"sub_categories":[],"readme":"# JSON-LD Generator\n\n[![Build Status](https://travis-ci.org/Torann/json-ld.svg)](https://travis-ci.org/Torann/json-ld)\n[![Latest Stable Version](https://poser.pugx.org/torann/json-ld/v/stable.png)](https://packagist.org/packages/torann/json-ld)\n[![Total Downloads](https://poser.pugx.org/torann/json-ld/downloads.png)](https://packagist.org/packages/torann/json-ld)\n[![Patreon donate button](https://img.shields.io/badge/patreon-donate-yellow.svg)](https://www.patreon.com/torann)\n[![Donate weekly to this project using Gratipay](https://img.shields.io/badge/gratipay-donate-yellow.svg)](https://liberapay.com/Torann/)\n[![Donate to this project using Flattr](https://img.shields.io/badge/flattr-donate-yellow.svg)](https://flattr.com/profile/torann)\n[![Donate to this project using Paypal](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=4CJA2A97NPYVU)\n\nExtremely simple JSON-LD generator.\n\n## Installation\n\n- [JSON-LD Generator on Packagist](https://packagist.org/packages/torann/json-ld)\n- [JSON-LD Generator on GitHub](https://github.com/Torann/json-ld)\n\nFrom the command line run\n\n```\n$ composer require torann/json-ld\n```\n\n## Methods\n\n **/JsonLd/Context.php**\n\n - `create($context, array $data = [])`\n - `getProperties()`\n - `generate()`\n\n## Context Types\n\n- article\n- audiobook\n- beach\n- blog_posting\n- book\n- breadcrumb_list\n- contact_point\n- corporation\n- creative_work\n- duration\n- event\n- geo_coordinates\n- image_object\n- invoice\n- list_item\n- local_business\n- media_object\n- music_album\n- music_group\n- music_playlist\n- music_recording\n- news_article\n- offer\n- order\n- organization\n- person\n- place\n- postal_address\n- price_specification\n- product\n- rating\n- recipe\n- review\n- sculpture\n- search_box\n- thing\n- video_object\n- web_page\n- web_site\n\n## Examples\n\n### Quick Example\n\n#### Business\n\n```php\n$context = \\JsonLd\\Context::create('local_business', [\n    'name' =\u003e 'Consectetur Adipiscing',\n    'description' =\u003e 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor',\n    'telephone' =\u003e '555-555-5555',\n    'openingHours' =\u003e 'mon,tue,fri',\n    'address' =\u003e [\n        'streetAddress' =\u003e '112 Apple St.',\n        'addressLocality' =\u003e 'Hamden',\n        'addressRegion' =\u003e 'CT',\n        'postalCode' =\u003e '06514',\n    ],\n    'geo' =\u003e [\n        'latitude' =\u003e '41.3958333',\n        'longitude' =\u003e '-72.8972222',\n    ],\n]);\n\necho $context; // Will output the script tag\n```\n\n### News Article\n\n```php\n$context = \\JsonLd\\Context::create('news_article', [\n    'headline' =\u003e 'Article headline',\n    'description' =\u003e 'A most wonderful article',\n    'mainEntityOfPage' =\u003e [\n        'url' =\u003e 'https://google.com/article',\n    ],\n    'image' =\u003e [\n        'url' =\u003e 'https://google.com/thumbnail1.jpg',\n        'height' =\u003e 800,\n        'width' =\u003e 800,\n    ],\n    'datePublished' =\u003e '2015-02-05T08:00:00+08:00',\n    'dateModified' =\u003e '2015-02-05T09:20:00+08:00',\n    'author' =\u003e [\n        'name' =\u003e 'John Doe',\n    ],\n    'publisher' =\u003e [\n        'name' =\u003e 'Google',\n        'logo' =\u003e [\n          'url' =\u003e 'https://google.com/logo.jpg',\n          'width' =\u003e 600,\n          'height' =\u003e 60,\n        ]\n    ],\n]);\n\necho $context; // Will output the script tag\n```\n\n### Using the JSON-LD in a Laracasts Presenter\n\nEven though this example shows using the JSON-LD inside of a `Laracasts\\Presenter` presenter, Laravel is not required for this package.\n\n#### /App/Presenters/BusinessPresenter.php\n\n```php\n\u003c?php\n\nnamespace App\\Presenters;\n\nuse JsonLd\\Context;\nuse Laracasts\\Presenter\\Presenter;\n\nclass BusinessPresenter extends Presenter\n{\n    /**\n     * Create JSON-LD object.\n     *\n     * @return \\JsonLd\\Context\n     */\n    public function jsonLd()\n    {\n        return Context::create('local_business', [\n            'name' =\u003e $this-\u003eentity-\u003ename,\n            'description' =\u003e $this-\u003eentity-\u003edescription,\n            'telephone' =\u003e $this-\u003eentity-\u003etelephone,\n            'openingHours' =\u003e 'mon,tue,fri',\n            'address' =\u003e [\n                'streetAddress' =\u003e $this-\u003eentity-\u003eaddress,\n                'addressLocality' =\u003e $this-\u003eentity-\u003ecity,\n                'addressRegion' =\u003e $this-\u003eentity-\u003estate,\n                'postalCode' =\u003e $this-\u003eentity-\u003epostalCode,\n            ],\n            'geo' =\u003e [\n                'latitude' =\u003e $this-\u003eentity-\u003elocation-\u003elat,\n                'longitude' =\u003e $this-\u003eentity-\u003elocation-\u003elng,\n            ],\n        ]);\n    }\n}\n```\n\n#### Generate the Tags\n\nThe generator comes with a `__toString` method that will automatically generate the correct script tags when displayed as a string.\n\n**Inside of a Laravel View**\n\n```php\necho $business-\u003epresent()-\u003ejsonLd();\n```\n\n**Inside of a Laravel View**\n\n```\n{!! $business-\u003epresent()-\u003ejsonLd() !!}\n```\n\n## Custom Context Type\n\nThe first argument for the `create($context, array $data = [])` method also accepts class names. This is helpful for custom context types.\n\n```php\n\u003c?php\n\nnamespace App\\JsonLd;\n\nuse JsonLd\\ContextTypes\\AbstractContext;\n\nclass FooBar extends AbstractContext\n{\n    /**\n     * Property structure\n     *\n     * @var array\n     */\n    protected $structure = [\n        'name' =\u003e null,\n        'description' =\u003e null,\n        'image' =\u003e null,\n        'url' =\u003e null,\n    ];\n}\n```\n\n```php\n$context = \\JsonLd\\Context::create(\\App\\JsonLd\\FooBar::class, [\n    'name' =\u003e 'Foo Foo headline',\n    'description' =\u003e 'Bar bar article description',\n    'url' =\u003e 'http://google.com',\n]);\n\necho $context; // Will output the script tag\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorann%2Fjson-ld","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftorann%2Fjson-ld","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorann%2Fjson-ld/lists"}