PHPackages                             punkstar/document-marshaller - 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. punkstar/document-marshaller

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

punkstar/document-marshaller
============================

A library for encoding and decoded structured data using JSON

0.1.0(9y ago)017MITPHP

Since Jul 4Pushed 9y agoCompare

[ Source](https://github.com/punkstar/document-marshaller)[ Packagist](https://packagist.org/packages/punkstar/document-marshaller)[ Docs](https://github.com/punkstar/document-marshaller)[ RSS](/packages/punkstar-document-marshaller/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Document Marshaller
===================

[](#document-marshaller)

[![Build Status](https://camo.githubusercontent.com/3f6115e062245c664f0831aad809b23df52186f00752fef04f87f760a96adba6/68747470733a2f2f7472617669732d63692e6f72672f70756e6b737461722f646f63756d656e742d6d61727368616c6c65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/punkstar/document-marshaller) [![Coverage Status](https://camo.githubusercontent.com/3c5de0acd505c92b284078c1334cac3216b058f18a79a820aa0ebf4f2930bdd5/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f70756e6b737461722f646f63756d656e742d6d61727368616c6c65722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/punkstar/document-marshaller?branch=master)

*This is an experiment - use at your own risk!*

The purpose of this library is provide a mechanism for marshalling and unmarshalling data using a single document, allowing for the transportation and storage of related data in a single file.

Notes on implementation:

- Booleans will be converted into integers

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

[](#installation)

```
composer require punkstar/document-marshaller

```

Usage
-----

[](#usage)

Create your document using `Document` and `DocumentFragment`, for example:

```
$document = new Document([
    new DocumentFragment("Fragment One", "This is the content in this fragment"),
    new DocumentFragment("Fragment Two", "This is the content in this fragment, the second")
]);

```

Create the marshallers and the checksum calculator:

```
$checksumCalculator = new Checksum();
$fragmentMarshaller = new DocumentFragment\Marshaller();

$marshaller = new DocumentMarshaller($fragmentMarshaller, $checksumCalculator);

```

The marshall the document:

```
$marshalledDocument = $marshaller->marshall($document);

```

Document Format
---------------

[](#document-format)

The document is encoded using JSON in the following structure:

```
{
    "v": "", // Document Version
    "c": ""  // Document Checksum
    "f": [   // Document Fragments
        {
            "n": "" // Document Fragment Name
            "d": "" // Document Fragment Data
        }
        ...
    ]
}

```

### Document

[](#document)

- A document MUST be an object.
- A document SHOULD have a version indicated by the value of the key: `v`. If a version is absent then a version value of `1` MUST be assumed.
- A document SHOULD have a checksum indicated by the value of the key: `c`. If a checksum is absent then any verification logic should be skipped and the user SHOULD be presented with a non fatal warning if appropriate.
- A document SHOULD have a fragments array indicated by the value of the key: `f`. If the fragments array is absent then it MUST be assumed that the document has no fragments.

### Document Version

[](#document-version)

- The document version MUST be expressed as an integer.

### Document Fragments

[](#document-fragments)

- The document fragments MUST be an array of objects with a name key: `n`, and a data key: `d`.
- The name and the data of the document fragment MUST be encoded with base64.

### Document Checksum

[](#document-checksum)

- The document checksum MUST be calculated by: sorting the fragments objects by name, then performing a hash of the JSON fragments array using sha256.

Some examples are provided below:

The first document consists of two fragments, one called `Header`; the other `Body`. The content of the `Header`fragment is the string `Hello`. The content of the `Body` fragment is `World`. The JSON representation of these fragments is as follows:

```
[
    {
        "n": "Header",
        "d": "Hello"
    },
    {
        "n": "Body",
        "d": "World"
    }
]

```

The checksum of this document would therefore be:

```
sha256([{"n":"SGVhZGVy","d":"SGVsbG8="},{"n":"Qm9keQ==","d":"V29ybGQ="}]) == "d827049039f82a8b65a9b0f52e637cf3bc5d1e0dec7d6198edf901a5e3dcae7d"

```

The entire document expressed would therefore be:

```
{

    "v": 1,
    "c": "d827049039f82a8b65a9b0f52e637cf3bc5d1e0dec7d6198edf901a5e3dcae7d",
    "f": [{
         "n": "Header",
         "d": "Hello"
     }, {
         "n": "Body",
         "d": "World"
    }]
}

```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3647d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/179072?v=4)[Nick Jones](/maintainers/punkstar)[@punkstar](https://github.com/punkstar)

---

Top Contributors

[![punkstar](https://avatars.githubusercontent.com/u/179072?v=4)](https://github.com/punkstar "punkstar (18 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/punkstar-document-marshaller/health.svg)

```
[![Health](https://phpackages.com/badges/punkstar-document-marshaller/health.svg)](https://phpackages.com/packages/punkstar-document-marshaller)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

46143.1k6](/packages/jstewmc-rtf)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

112.9k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

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