PHPackages                             daverandom/jom - 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. daverandom/jom

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

daverandom/jom
==============

A DOM-like API for working for JSON

2112PHP

Since Aug 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/DaveRandom/JOM)[ Packagist](https://packagist.org/packages/daverandom/jom)[ RSS](/packages/daverandom-jom/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

JOM - JSON Object Model
=======================

[](#jom---json-object-model)

A DOM-like API for working with JSON data, including an [RFC 6901 JSON pointer](https://tools.ietf.org/html/rfc6901)implementation with the [draft relative JSON pointer](https://tools.ietf.org/html/draft-luff-relative-json-pointer-00)extension.

Status
------

[](#status)

[![Build Status](https://camo.githubusercontent.com/9fc3e7b41a7a25e217253a90e1d80e54be5d7ff89e8a44ecb602884e2171b87f/68747470733a2f2f7472617669732d63692e6f72672f4461766552616e646f6d2f4a4f4d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/DaveRandom/JOM)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/792c1856175698323f13c7f9627982b855719612a03a2d10a5088bd19e1b497c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4461766552616e646f6d2f4a4f4d2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/DaveRandom/JOM/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/d1e9d9683326bcd041c9845fdd3b874d584ae5143f752b4f9b48c22f0119cdb1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4461766552616e646f6d2f4a4f4d2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/DaveRandom/JOM/?branch=master)

API
---

[](#api)

### [Document](https://github.com/DaveRandom/JOM/blob/master/src/Document.php)

[](#document)

```
final class \DaveRandom\Jom\Document
    implements \JsonSerializable
{
    /**
     * Create a Document instance from a JSON string, forwarding arguments to json_encode().
     *
     * @throws ParseFailureException when the supplied string cannot be parsed as JSON.
     * @throws DocumentTreeCreationFailedException when a document tree cannot be built from the parsed data.
     */
    public static Document parse(string $json, int $depthLimit = 512, int $options = 0);

    /**
     * Create a Document instance from a PHP value.
     *
     * @throws DocumentTreeCreationFailedException when a document tree cannot be built from the supplied data.
     */
    public static Document createFromValue($value);

    /**
     * Returns the root node of the document, or NULL if the document is empty.
     */
    public ?Node getRootNode();

    /**
     * Evaluate a JSON pointer against the document tree.
     *
     * @throws InvalidPointerException when the supplied pointer string is invalid
     * @throws PointerEvaluationFailureException when the pointer does not indicate an existing node
     * @throws InvalidSubjectNodeException when the $base node is not part of the document
     */
    public Node|int|string evaluatePointer(Pointer|string $pointer, Node $base = null);
}
```

### [Node](https://github.com/DaveRandom/JOM/blob/master/src/Node.php)

[](#node)

```
/**
 * NOTE: Classes inheriting from Node that are not provided by this library will result in undefined behaviour.
 */
abstract class \DaveRandom\Jom\Node
    implements \JsonSerializable
{
    /**
     * Create a Node instance from a PHP value.
     *
     * @throws InvalidNodeValueException when a Node cannot be built from the supplied data.
     */
    public static Node createFromValue($value);

    /**
     * Returns the parent node of this node, or NULL if this is the root node or the node is not present in the
     * owning document.
     */
    public ?Node getParent();

    /**
     * Returns the next sibling node of this node, or NULL if the node does not have a following sibling node.
     */
    public ?Node getPreviousSibling();

    /**
     * Returns the previous sibling node of this node, or NULL if the node does not have a preceding sibling node.
     */
    public ?Node getNextSibling();

    /**
     * Returns TRUE if this node has child nodes, otherwise FALSE.
     */
    public bool hasChildren();

    /**
     * Returns the first child node of this node, or NULL if the node does not have any child nodes.
     */
    public ?Node getFirstChild();

    /**
     * Returns the last child node of this node, or NULL if the node does not have any child nodes.
     */
    public ?Node getLastChild();

    /**
     * Returns the Document object that owns this node.
     */
    public ?Document getOwnerDocument();

    /**
     * Get a JSON pointer for this node's position in the document. If the $base node is supplied, get a relative
     * pointer.
     *
     * @throws InvalidSubjectNodeException when the $base node is invalid
     */
    public Pointer getPointer(Node $base = null);

    /**
     * Returns the key of this node within its parent node, or NULL if this is the root node of the document.
     */
    public string|int|null getKey();

    /**
     * Returns the data represented by this node as the appropriate PHP type.
     */
    public mixed getValue();
}
```

### [NullNode](https://github.com/DaveRandom/JOM/blob/master/src/NullNode.php)

[](#nullnode)

```
final class \DaveRandom\Jom\NullNode extends \DaveRandom\Jom\Node
{
    /**
     * Create a new NULL value node owned by the supplied document.
     */
    public __construct(?Document $ownerDocument = null);
}
```

### [BooleanNode](https://github.com/DaveRandom/JOM/blob/master/src/BooleanNode.php)

[](#booleannode)

```
final class \DaveRandom\Jom\BooleanNode extends \DaveRandom\Jom\Node
{
    /**
     * Create a new boolean value node owned by the supplied document.
     */
    public __construct(?bool $value = false, ?Document $ownerDocument = null);

    /**
     * Set the value of this node
     */
    public void setValue(bool $value);
}
```

### [NumberNode](https://github.com/DaveRandom/JOM/blob/master/src/NumberNode.php)

[](#numbernode)

```
final class \DaveRandom\Jom\NumberNode extends \DaveRandom\Jom\Node
{
    /**
     * Create a new number value node owned by the supplied document.
     */
    public __construct(int|float|null $value = 0, ?Document $ownerDocument = null);

    /**
     * Set the value of this node
     */
    public void setValue(int|float $value);
}
```

### [StringNode](https://github.com/DaveRandom/JOM/blob/master/src/StringNode.php)

[](#stringnode)

```
final class \DaveRandom\Jom\StringNode extends \DaveRandom\Jom\Node
{
    /**
     * Create a new string value node owned by the supplied document.
     */
    public __construct(?string $value = "", ?Document $ownerDocument = null);

    /**
     * Set the value of this node
     */
    public void setValue(string $value);
}
```

### [VectorNode](https://github.com/DaveRandom/JOM/blob/master/src/VectorNode.php)

[](#vectornode)

```
/**
 * NOTE: Classes inheriting from VectorNode that are not provided by this library will result in undefined
 * behaviour.
 */
abstract class \DaveRandom\Jom\VectorNode extends \DaveRandom\Jom\Node
    implements \Countable, \IteratorAggregate, \ArrayAccess
{
    /**
     * Returns the data represented by this node as an array.
     */
    public array toArray();

    /**
     * Remove all child nodes.
     */
    public void clear();
}
```

### [ArrayNode](https://github.com/DaveRandom/JOM/blob/master/src/ArrayNode.php)

[](#arraynode)

```
final class \DaveRandom\Jom\ArrayNode extends \DaveRandom\Jom\VectorNode
{
    /**
     * Create a new array node owned by the supplied document.
     */
    public __construct(Node[] $values = null, ?Document $ownerDocument = null);

    /**
     * Append one or more nodes to the array.
     *
     * @throws EmptySubjectNodeListException when no nodes are supplied
     * @throws InvalidSubjectNodeException when one of the supplied nodes is invalid.
     * @throws WriteOperationForbiddenException when there is an active iterator for the array.
     */
    public void push(Node ...$nodes);

    /**
     * Remove the last node from the array, if any, and return it.
     *
     * @throws WriteOperationForbiddenException when there is an active iterator for the array.
     */
    public ?Node pop();

    /**
     * Prepend one or more nodes to the array.
     *
     * @throws EmptySubjectNodeListException when no nodes are supplied
     * @throws InvalidSubjectNodeException when one of the supplied nodes is invalid.
     * @throws WriteOperationForbiddenException when there is an active iterator for the array.
     */
    public void unshift(Node ...$nodes);

    /**
     * Remove the first node from the array, if any, and return it.
     *
     * @throws WriteOperationForbiddenException when there is an active iterator for the array.
     */
    public ?Node shift();

    /**
     * Insert a new node before the supplied reference node. If $beforeNode is NULL it is equivalent to push().
     *
     * @throws InvalidSubjectNodeException when $node is invalid.
     * @throws InvalidReferenceNodeException when $beforeNode is not a member of the array
     * @throws WriteOperationForbiddenException when there is an active iterator for the array.
     */
    public void insert(Node $node, ?Node $beforeNode);

    /**
     * Replace an existing node object or the node at the supplied index with a new node.
     *
     * @throws InvalidSubjectNodeException when $newNode is invalid.
     * @throws InvalidReferenceNodeException when $nodeOrIndex is not a member of the array
     * @throws WriteOperationForbiddenException when there is an active iterator for the array.
     */
    public void replace(Node|int $nodeOrIndex, Node $newNode);

    /**
     * Remove the supplied node from the array.
     *
     * @throws WriteOperationForbiddenException when there is an active iterator for the array.
     * @throws InvalidSubjectNodeException when $node is not a member of the array.
     */
    public void remove(Node $node);
}
```

### [ObjectNode](https://github.com/DaveRandom/JOM/blob/master/src/ObjectNode.php)

[](#objectnode)

```
final class \DaveRandom\Jom\ObjectNode extends \DaveRandom\Jom\VectorNode
{
    /**
     * Create a new array node owned by the supplied document.
     */
    public __construct(Node[] $properties = null, ?Document $ownerDocument = null);

    /**
     * Returns a list of the object's property names.
     */
    public string[] getPropertyNames();

    /**
     * Returns TRUE if the object has a property with the supplied name, otherwise FALSE.
     */
    public bool hasProperty(string $name);

    /**
     * Get the value node associated with the supplied property name.
     *
     * @throws InvalidKeyException when the property does not exist.
     */
    public Node getProperty(string $name);

    /**
     * Set the value node associated with the supplied property name.
     *
     * @throws InvalidSubjectNodeException when $value is invalid.
     * @throws WriteOperationForbiddenException when there is an active iterator for the array.
     */
    public void setProperty(string $name, Node $value);

    /**
     * Remove the supplied property.
     *
     * @throws InvalidSubjectNodeException when $nodeOrName is a Node that is not a property of the object.
     * @throws InvalidKeyException when $nodeOrName is the name of a property that does not exist.
     * @throws WriteOperationForbiddenException when there is an active iterator for the array.
     */
    public void removeProperty(Node|string $nodeOrName);
}
```

### Exception Hierarchy

[](#exception-hierarchy)

```
\Exception
  └ \DaveRandom\Jom\Exceptions\Exception Ⓐ
      ├ \DaveRandom\Jom\Exceptions\DocumentTreeCreationFailedException Ⓕ
      ├ \DaveRandom\Jom\Exceptions\InvalidNodeValueException Ⓕ
      ├ \DaveRandom\Jom\Exceptions\InvalidOperationException Ⓐ
      │   ├ \DaveRandom\Jom\Exceptions\EmptySubjectNodeListException Ⓕ
      │   ├ \DaveRandom\Jom\Exceptions\InvalidKeyException Ⓕ
      │   ├ \DaveRandom\Jom\Exceptions\InvalidReferenceNodeException Ⓕ
      │   ├ \DaveRandom\Jom\Exceptions\InvalidSubjectNodeException Ⓕ
      │   └ \DaveRandom\Jom\Exceptions\WriteOperationForbiddenException Ⓕ
      ├ \DaveRandom\Jom\Exceptions\InvalidPointerException Ⓕ
      ├ \DaveRandom\Jom\Exceptions\ParseFailureException Ⓕ
      └ \DaveRandom\Jom\Exceptions\PointerEvaluationFailureException Ⓕ

```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity40

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb9d79bcd4c3c02b52daba8a5371a4d710286d9b7472c8d922008c48999d76b9?d=identicon)[DaveRandom](/maintainers/DaveRandom)

---

Top Contributors

[![DaveRandom](https://avatars.githubusercontent.com/u/2396425?v=4)](https://github.com/DaveRandom "DaveRandom (73 commits)")

### Embed Badge

![Health badge](/badges/daverandom-jom/health.svg)

```
[![Health](https://phpackages.com/badges/daverandom-jom/health.svg)](https://phpackages.com/packages/daverandom-jom)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

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