PHPackages                             brick/structured-data - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. brick/structured-data

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

brick/structured-data
=====================

Microdata, RDFa Lite &amp; JSON-LD structured data reader

0.2.0(11mo ago)26162.8k—0.1%10[5 PRs](https://github.com/brick/structured-data/pulls)1MITPHPPHP ^8.1CI passing

Since Oct 14Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/brick/structured-data)[ Packagist](https://packagist.org/packages/brick/structured-data)[ GitHub Sponsors](https://github.com/BenMorel)[ RSS](/packages/brick-structured-data/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (6)Used By (1)

Brick\\StructuredData
---------------------

[](#brickstructureddata)

[![](https://raw.githubusercontent.com/brick/brick/master/logo.png)](https://raw.githubusercontent.com/brick/brick/master/logo.png)

A PHP library to read Microdata, RDFa Lite &amp; JSON-LD structured data in HTML pages.

This library is a foundation to read schema.org structured data in [brick/schema](https://github.com/brick/schema), but may be used with other vocabularies.

[![Build Status](https://github.com/brick/structured-data/workflows/CI/badge.svg)](https://github.com/brick/structured-data/actions)[![Coverage Status](https://camo.githubusercontent.com/18d08b095a39df3bdfcc752cb6cd83424180c70066673672efbecb7a82478b37/68747470733a2f2f636f6465636f762e696f2f6769746875622f627269636b2f737472756374757265642d646174612f67726170682f62616467652e737667)](https://codecov.io/github/brick/structured-data)[![Latest Stable Version](https://camo.githubusercontent.com/2c9329d8b92522c89f494ad67672c00db9b1b7b4552159f75f329ea5f87804f1/68747470733a2f2f706f7365722e707567782e6f72672f627269636b2f737472756374757265642d646174612f762f737461626c65)](https://packagist.org/packages/brick/structured-data)[![Total Downloads](https://camo.githubusercontent.com/14a2e97266e9c1ae1b3c2a92f222aa17a85fe063ce8ad4c2a2f7fa64f34ef3fb/68747470733a2f2f706f7365722e707567782e6f72672f627269636b2f737472756374757265642d646174612f646f776e6c6f616473)](https://packagist.org/packages/brick/structured-data)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](http://opensource.org/licenses/MIT)

### Installation

[](#installation)

This library is installable via [Composer](https://getcomposer.org/):

```
composer require brick/structured-data
```

### Requirements

[](#requirements)

This library requires PHP 8.1 or later. It makes use of the following extensions:

- [dom](https://www.php.net/manual/en/book.dom.php)
- [json](https://www.php.net/manual/en/book.json.php)
- [libxml](https://www.php.net/manual/en/book.libxml.php)

These extensions are enabled by default, and should be available in most PHP installations.

### Project status &amp; release process

[](#project-status--release-process)

This library is under development. It is likely to change fast in the early `0.x` releases. However, the library follows a strict BC break convention:

The current releases are numbered `0.x.y`. When a non-breaking change is introduced (adding new methods, fixing bugs, optimizing existing code, etc.), `y` is incremented.

**When a breaking change is introduced, a new `0.x` version cycle is always started.**

It is therefore safe to lock your project to a given release cycle, such as `0.2.*`.

If you need to upgrade to a newer release cycle, check the [release history](https://github.com/brick/structured-data/releases)for a list of changes introduced by each further `0.x.0` version.

### Introduction

[](#introduction)

The library unifies reading the 3 supported formats (Microdata, RDFa Lite &amp; JSON-LD) under a common interface:

```
interface Brick\StructuredData\Reader
{
    /**
     * Reads the items contained in the given document.
     *
     * @param DOMDocument $document The DOM document to read.
     * @param string      $url      The URL the document was retrieved from. This will be used only to resolve relative
     *                              URLs in property values. No attempt will be performed to connect to this URL.
     *
     * @return Item[] The top-level items.
     */
    public function read(DOMDocument $document, string $url) : array;
}
```

There are 3 implementations of this interface, one for each format:

- `MicrodataReader`
- `RdfaLiteReader`
- `JsonLdReader`

The `read()` method returns the top-level items found in the document. Every `Item` consists of:

- An optional id (`itemid` in Microdata, `resource` in RDFa Lite, `@id` in JSON-LD)
- An array of zero or more types; each type is a URL, for example `http://schema.org/Product`
- An associative array of zero or more properties; each property has a URL as a key, for example `http://schema.org/price`, and maps to an array of one or more values; values can be plain strings, or nested `Item` objects

### Quickstart

[](#quickstart)

Here is a working example that reads Microdata from a web page. Just change the URL and give it a try:

```
use Brick\StructuredData\Reader\MicrodataReader;
use Brick\StructuredData\HTMLReader;
use Brick\StructuredData\Item;

// Let's read Microdata here;
// You could also use RdfaLiteReader, JsonLdReader,
// or even use all of them by chaining them in a ReaderChain
$microdataReader = new MicrodataReader();

// Wrap into HTMLReader to be able to read HTML strings or files directly,
// i.e. without manually converting them to DOMDocument instances first
$htmlReader = new HTMLReader($microdataReader);

// Replace this URL with that of a website you know is using Microdata
$url = 'http://www.example.com/';
$html = file_get_contents($url);

// Read the document and return the top-level items found
// Note: the URL is only required to resolve relative URLs; no attempt will be made to connect to it
$items = $htmlReader->read($html, $url);

// Loop through the top-level items
foreach ($items as $item) {
    echo implode(',', $item->getTypes()), PHP_EOL;

    foreach ($item->getProperties() as $name => $values) {
        foreach ($values as $value) {
            if ($value instanceof Item) {
                // We're only displaying the class name in this example; you would typically
                // recurse through nested Items to get the information you need
                $value = '(' . implode(', ', $value->getTypes()) . ')';
            }

            // If $value is not an Item, then it's a plain string

            echo "  - $name: $value", PHP_EOL;
        }
    }
}
```

### Current limitations

[](#current-limitations)

- No support for the `itemref` attribute in `MicroDataReader`
- No support for the `prefix` attribute in `RdfaLiteReader`; only [predefined prefixes](https://www.w3.org/2011/rdfa-context/rdfa-1.1) are supported right now
- No proper support for `@context` in `JsonLdReader`; right now, only strings are accepted in `@context`, and they are considered a vocabulary identifier; this works fine with simple markup like the one used in the examples on [schema.org](https://schema.org/), but may fail with more complex documents.

#### Note about JSON-LD's `@context`

[](#note-about-json-lds-context)

While `JsonLdReader` should be able to handle a proper context object in the future, its goal will never be to be a fully compliant JSON-LD parser; in particular, it will *never* attempt to fetch a JSON-LD context referenced by a URL.

This is consistent with how indexing robots typically crawl the web, they do not fetch remote contexts, which relieves them from fetching additional documents to extract structured data from a web page.

The aim of `JsonLdReader`, and the other `Reader` implementations for that matter, is to be able to parse a document with the same capabilities as [Google Structured Data Testing Tool](https://search.google.com/structured-data/testing-tool/) or [Yandex Structured data validator](https://webmaster.yandex.com/tools/microtest/), no more, no less. These tools [do not load external context files](https://webmasters.stackexchange.com/q/123425/18342).

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance72

Regular maintenance activity

Popularity45

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 98.8% 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 ~1033 days

Total

3

Last Release

342d ago

PHP version history (3 changes)0.1.0PHP &gt;=7.2

0.1.1PHP ^7.2 || ^8.0

0.2.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/57189121968030f0770811b461cc92f9c19c08f5c4767292f2ede48b7277cfad?d=identicon)[BenMorel](/maintainers/BenMorel)

---

Top Contributors

[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (81 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (1 commits)")

---

Tags

brickJSON-LDrdfastructured-datamicrodata

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/brick-structured-data/health.svg)

```
[![Health](https://phpackages.com/badges/brick-structured-data/health.svg)](https://phpackages.com/packages/brick-structured-data)
```

###  Alternatives

[brick/schema

Schema.org library for PHP

5163.7k1](/packages/brick-schema)[digitalbazaar/json-ld

A JSON-LD Processor and API implementation in PHP.

28555.4k1](/packages/digitalbazaar-json-ld)[brick/json-mapper

Maps JSON data to strongly typed PHP DTOs

20552.1k3](/packages/brick-json-mapper)[torann/json-ld

Extremely simple JSON-LD markup generator.

149620.7k1](/packages/torann-json-ld)[simialbi/yii2-schema-org

Schema.org yii2 representation and helpers for json-ld generation in Yii framework

18102.7k4](/packages/simialbi-yii2-schema-org)[wikimedia/purtle

Fast streaming RDF serializer

11698.1k1](/packages/wikimedia-purtle)

PHPackages © 2026

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