{"id":19527364,"url":"https://github.com/daverandom/jom","last_synced_at":"2025-04-26T10:31:49.184Z","repository":{"id":56963183,"uuid":"134869872","full_name":"DaveRandom/JOM","owner":"DaveRandom","description":"A DOM-like API for working with JSON","archived":false,"fork":false,"pushed_at":"2018-08-23T19:05:51.000Z","size":83,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T11:51:10.247Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DaveRandom.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-25T14:54:29.000Z","updated_at":"2019-01-19T08:57:43.000Z","dependencies_parsed_at":"2022-08-21T09:50:42.096Z","dependency_job_id":null,"html_url":"https://github.com/DaveRandom/JOM","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveRandom%2FJOM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveRandom%2FJOM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveRandom%2FJOM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveRandom%2FJOM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DaveRandom","download_url":"https://codeload.github.com/DaveRandom/JOM/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250973015,"owners_count":21516461,"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":[],"created_at":"2024-11-11T01:14:44.810Z","updated_at":"2025-04-26T10:31:48.865Z","avatar_url":"https://github.com/DaveRandom.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JOM - JSON Object Model\n\nA DOM-like API for working with JSON data, including an [RFC 6901 JSON pointer](https://tools.ietf.org/html/rfc6901)\nimplementation with the [draft relative JSON pointer](https://tools.ietf.org/html/draft-luff-relative-json-pointer-00)\nextension.\n\n## Status\n\n[![Build Status](https://travis-ci.org/DaveRandom/JOM.svg?branch=master)](https://travis-ci.org/DaveRandom/JOM)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/DaveRandom/JOM/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/DaveRandom/JOM/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/DaveRandom/JOM/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/DaveRandom/JOM/?branch=master)\n\n## API\n\n### [Document](https://github.com/DaveRandom/JOM/blob/master/src/Document.php)\n\n```php\nfinal class \\DaveRandom\\Jom\\Document\n    implements \\JsonSerializable\n{\n    /**\n     * Create a Document instance from a JSON string, forwarding arguments to json_encode().\n     *\n     * @throws ParseFailureException when the supplied string cannot be parsed as JSON.\n     * @throws DocumentTreeCreationFailedException when a document tree cannot be built from the parsed data.\n     */\n    public static Document parse(string $json, int $depthLimit = 512, int $options = 0);\n\n    /**\n     * Create a Document instance from a PHP value.\n     *\n     * @throws DocumentTreeCreationFailedException when a document tree cannot be built from the supplied data.\n     */\n    public static Document createFromValue($value);\n\n    /**\n     * Returns the root node of the document, or NULL if the document is empty.\n     */\n    public ?Node getRootNode();\n\n    /**\n     * Evaluate a JSON pointer against the document tree.\n     *\n     * @throws InvalidPointerException when the supplied pointer string is invalid\n     * @throws PointerEvaluationFailureException when the pointer does not indicate an existing node\n     * @throws InvalidSubjectNodeException when the $base node is not part of the document\n     */\n    public Node|int|string evaluatePointer(Pointer|string $pointer, Node $base = null);\n}\n```\n\n### [Node](https://github.com/DaveRandom/JOM/blob/master/src/Node.php)\n\n```php\n/**\n * NOTE: Classes inheriting from Node that are not provided by this library will result in undefined behaviour.\n */\nabstract class \\DaveRandom\\Jom\\Node\n    implements \\JsonSerializable\n{\n    /**\n     * Create a Node instance from a PHP value.\n     *\n     * @throws InvalidNodeValueException when a Node cannot be built from the supplied data.\n     */\n    public static Node createFromValue($value);\n\n    /**\n     * Returns the parent node of this node, or NULL if this is the root node or the node is not present in the\n     * owning document.\n     */\n    public ?Node getParent();\n\n    /**\n     * Returns the next sibling node of this node, or NULL if the node does not have a following sibling node.\n     */\n    public ?Node getPreviousSibling();\n\n    /**\n     * Returns the previous sibling node of this node, or NULL if the node does not have a preceding sibling node.\n     */\n    public ?Node getNextSibling();\n\n    /**\n     * Returns TRUE if this node has child nodes, otherwise FALSE.\n     */\n    public bool hasChildren();\n\n    /**\n     * Returns the first child node of this node, or NULL if the node does not have any child nodes.\n     */\n    public ?Node getFirstChild();\n\n    /**\n     * Returns the last child node of this node, or NULL if the node does not have any child nodes.\n     */\n    public ?Node getLastChild();\n\n    /**\n     * Returns the Document object that owns this node.\n     */\n    public ?Document getOwnerDocument();\n\n    /**\n     * Get a JSON pointer for this node's position in the document. If the $base node is supplied, get a relative\n     * pointer.\n     *\n     * @throws InvalidSubjectNodeException when the $base node is invalid\n     */\n    public Pointer getPointer(Node $base = null);\n\n    /**\n     * Returns the key of this node within its parent node, or NULL if this is the root node of the document.\n     */\n    public string|int|null getKey();\n\n    /**\n     * Returns the data represented by this node as the appropriate PHP type.\n     */\n    public mixed getValue();\n}\n```\n\n### [NullNode](https://github.com/DaveRandom/JOM/blob/master/src/NullNode.php)\n\n```php\nfinal class \\DaveRandom\\Jom\\NullNode extends \\DaveRandom\\Jom\\Node\n{\n    /**\n     * Create a new NULL value node owned by the supplied document.\n     */\n    public __construct(?Document $ownerDocument = null);\n}\n```\n\n### [BooleanNode](https://github.com/DaveRandom/JOM/blob/master/src/BooleanNode.php)\n\n```php\nfinal class \\DaveRandom\\Jom\\BooleanNode extends \\DaveRandom\\Jom\\Node\n{\n    /**\n     * Create a new boolean value node owned by the supplied document.\n     */\n    public __construct(?bool $value = false, ?Document $ownerDocument = null);\n\n    /**\n     * Set the value of this node\n     */\n    public void setValue(bool $value);\n}\n```\n\n### [NumberNode](https://github.com/DaveRandom/JOM/blob/master/src/NumberNode.php)\n\n```php\nfinal class \\DaveRandom\\Jom\\NumberNode extends \\DaveRandom\\Jom\\Node\n{\n    /**\n     * Create a new number value node owned by the supplied document.\n     */\n    public __construct(int|float|null $value = 0, ?Document $ownerDocument = null);\n\n    /**\n     * Set the value of this node\n     */\n    public void setValue(int|float $value);\n}\n```\n\n### [StringNode](https://github.com/DaveRandom/JOM/blob/master/src/StringNode.php)\n\n```php\nfinal class \\DaveRandom\\Jom\\StringNode extends \\DaveRandom\\Jom\\Node\n{\n    /**\n     * Create a new string value node owned by the supplied document.\n     */\n    public __construct(?string $value = \"\", ?Document $ownerDocument = null);\n\n    /**\n     * Set the value of this node\n     */\n    public void setValue(string $value);\n}\n```\n\n### [VectorNode](https://github.com/DaveRandom/JOM/blob/master/src/VectorNode.php)\n\n```php\n/**\n * NOTE: Classes inheriting from VectorNode that are not provided by this library will result in undefined\n * behaviour.\n */\nabstract class \\DaveRandom\\Jom\\VectorNode extends \\DaveRandom\\Jom\\Node \n    implements \\Countable, \\IteratorAggregate, \\ArrayAccess\n{\n    /**\n     * Returns the data represented by this node as an array.\n     */\n    public array toArray();\n    \n    /**\n     * Remove all child nodes.\n     */\n    public void clear();\n}\n```\n\n### [ArrayNode](https://github.com/DaveRandom/JOM/blob/master/src/ArrayNode.php)\n\n```php\nfinal class \\DaveRandom\\Jom\\ArrayNode extends \\DaveRandom\\Jom\\VectorNode\n{\n    /**\n     * Create a new array node owned by the supplied document.\n     */\n    public __construct(Node[] $values = null, ?Document $ownerDocument = null);\n\n    /**\n     * Append one or more nodes to the array.\n     *\n     * @throws EmptySubjectNodeListException when no nodes are supplied \n     * @throws InvalidSubjectNodeException when one of the supplied nodes is invalid.\n     * @throws WriteOperationForbiddenException when there is an active iterator for the array.\n     */\n    public void push(Node ...$nodes);\n\n    /**\n     * Remove the last node from the array, if any, and return it.\n     *\n     * @throws WriteOperationForbiddenException when there is an active iterator for the array.\n     */\n    public ?Node pop();\n\n    /**\n     * Prepend one or more nodes to the array.\n     *\n     * @throws EmptySubjectNodeListException when no nodes are supplied \n     * @throws InvalidSubjectNodeException when one of the supplied nodes is invalid.\n     * @throws WriteOperationForbiddenException when there is an active iterator for the array.\n     */\n    public void unshift(Node ...$nodes);\n\n    /**\n     * Remove the first node from the array, if any, and return it.\n     *\n     * @throws WriteOperationForbiddenException when there is an active iterator for the array.\n     */\n    public ?Node shift();\n\n    /**\n     * Insert a new node before the supplied reference node. If $beforeNode is NULL it is equivalent to push().\n     *\n     * @throws InvalidSubjectNodeException when $node is invalid.\n     * @throws InvalidReferenceNodeException when $beforeNode is not a member of the array\n     * @throws WriteOperationForbiddenException when there is an active iterator for the array.\n     */\n    public void insert(Node $node, ?Node $beforeNode);\n\n    /**\n     * Replace an existing node object or the node at the supplied index with a new node.\n     *\n     * @throws InvalidSubjectNodeException when $newNode is invalid.\n     * @throws InvalidReferenceNodeException when $nodeOrIndex is not a member of the array\n     * @throws WriteOperationForbiddenException when there is an active iterator for the array.\n     */\n    public void replace(Node|int $nodeOrIndex, Node $newNode);\n\n    /**\n     * Remove the supplied node from the array.\n     *\n     * @throws WriteOperationForbiddenException when there is an active iterator for the array.\n     * @throws InvalidSubjectNodeException when $node is not a member of the array.\n     */\n    public void remove(Node $node);\n}\n```\n\n### [ObjectNode](https://github.com/DaveRandom/JOM/blob/master/src/ObjectNode.php)\n\n```php\nfinal class \\DaveRandom\\Jom\\ObjectNode extends \\DaveRandom\\Jom\\VectorNode\n{\n    /**\n     * Create a new array node owned by the supplied document.\n     */\n    public __construct(Node[] $properties = null, ?Document $ownerDocument = null);\n\n    /**\n     * Returns a list of the object's property names.\n     */\n    public string[] getPropertyNames();\n\n    /**\n     * Returns TRUE if the object has a property with the supplied name, otherwise FALSE.\n     */\n    public bool hasProperty(string $name);\n\n    /**\n     * Get the value node associated with the supplied property name.\n     *\n     * @throws InvalidKeyException when the property does not exist.\n     */\n    public Node getProperty(string $name);\n\n    /**\n     * Set the value node associated with the supplied property name.\n     *\n     * @throws InvalidSubjectNodeException when $value is invalid.\n     * @throws WriteOperationForbiddenException when there is an active iterator for the array.\n     */\n    public void setProperty(string $name, Node $value);\n\n    /**\n     * Remove the supplied property.\n     *\n     * @throws InvalidSubjectNodeException when $nodeOrName is a Node that is not a property of the object.\n     * @throws InvalidKeyException when $nodeOrName is the name of a property that does not exist.\n     * @throws WriteOperationForbiddenException when there is an active iterator for the array.\n     */\n    public void removeProperty(Node|string $nodeOrName);\n}\n```\n\n### Exception Hierarchy\n\n```\n\\Exception\n  └ \\DaveRandom\\Jom\\Exceptions\\Exception Ⓐ\n      ├ \\DaveRandom\\Jom\\Exceptions\\DocumentTreeCreationFailedException Ⓕ\n      ├ \\DaveRandom\\Jom\\Exceptions\\InvalidNodeValueException Ⓕ\n      ├ \\DaveRandom\\Jom\\Exceptions\\InvalidOperationException Ⓐ\n      │   ├ \\DaveRandom\\Jom\\Exceptions\\EmptySubjectNodeListException Ⓕ\n      │   ├ \\DaveRandom\\Jom\\Exceptions\\InvalidKeyException Ⓕ\n      │   ├ \\DaveRandom\\Jom\\Exceptions\\InvalidReferenceNodeException Ⓕ\n      │   ├ \\DaveRandom\\Jom\\Exceptions\\InvalidSubjectNodeException Ⓕ\n      │   └ \\DaveRandom\\Jom\\Exceptions\\WriteOperationForbiddenException Ⓕ\n      ├ \\DaveRandom\\Jom\\Exceptions\\InvalidPointerException Ⓕ\n      ├ \\DaveRandom\\Jom\\Exceptions\\ParseFailureException Ⓕ\n      └ \\DaveRandom\\Jom\\Exceptions\\PointerEvaluationFailureException Ⓕ\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaverandom%2Fjom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaverandom%2Fjom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaverandom%2Fjom/lists"}