PHPackages                             dd/evolutioncms-snippets-ddobjecttools - 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. dd/evolutioncms-snippets-ddobjecttools

ActiveModxevo-snippet[Parsing &amp; Serialization](/categories/parsing)

dd/evolutioncms-snippets-ddobjecttools
======================================

Tools for modifying objects.

1.0.0(1y ago)01PHPPHP &gt;=5.6.0

Since Apr 23Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/DivanDesign/EvolutionCMS.snippets.ddObjectTools)[ Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddobjecttools)[ Docs](https://code.divandesign.ru/modx/ddobjecttools)[ RSS](/packages/dd-evolutioncms-snippets-ddobjecttools/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (8)Dependencies (1)Versions (10)Used By (0)

(MODX)EvolutionCMS.snippets.ddObjectTools
=========================================

[](#modxevolutioncmssnippetsddobjecttools)

Tools for modifying objects.

Requires
--------

[](#requires)

- PHP &gt;= 5.6
- [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) &gt;= 1.1
- [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.ru/modx/ddtools) &gt;= 0.62

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

[](#installation)

### Using [(MODX)EvolutionCMS.libraries.ddInstaller](https://github.com/DivanDesign/EvolutionCMS.libraries.ddInstaller)

[](#using-modxevolutioncmslibrariesddinstaller)

Just run the following PHP code in your sources or [Console](https://github.com/vanchelo/MODX-Evolution-Ajax-Console):

```
//Include (MODX)EvolutionCMS.libraries.ddInstaller
require_once(
	$modx->getConfig('base_path') .
	'assets/libs/ddInstaller/require.php'
);

//Install (MODX)EvolutionCMS.snippets.ddObjectTools
\DDInstaller::install([
	'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddObjectTools',
	'type' => 'snippet',
]);
```

- If `ddObjectTools` is not exist on your site, `ddInstaller` will just install it.
- If `ddObjectTools` is already exist on your site, `ddInstaller` will check it version and update it if needed.

### Manually

[](#manually)

#### 1. Elements → Snippets: Create a new snippet with the following data

[](#1-elements--snippets-create-a-new-snippet-with-the-following-data)

1. Snippet name: `ddObjectTools`.
2. Description: `1.0 Tools for modifying objects.`.
3. Category: `Core`.
4. Parse DocBlock: `no`.
5. Snippet code (php): Insert content of the `ddObjectTools_snippet.php` file from the archive.

#### 2. Elements → Manage Files

[](#2-elements--manage-files)

1. Create a new folder `assets/snippets/ddObjectTools/`.
2. Extract the archive to the folder (except `ddObjectTools_snippet.php`).

Parameters description
----------------------

[](#parameters-description)

- `sourceObject`

    - Description: Source object or array.
    - Valid values:
        - `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
        - `stringJsonArray` — as [JSON](https://en.wikipedia.org/wiki/JSON)
        - `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
        - `stringHjsonArray` — as [HJSON](https://hjson.github.io/)
        - `stringQueryFormatted` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
        - It can also be set as a native PHP object or array (e. g. for calls through `$modx->runSnippet`):
            - `array`
            - `object`
    - Default value: `'{}'`
- `extend`

    - Description: Merge the contents of two or more objects / arrays together into `sourceObject` (it will receive the new properties).
    - Valid values:
        - `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
        - `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
        - `stringQueryFormatted` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
        - It can also be set as a native PHP object or array (e. g. for calls through `$modx->runSnippet`):
            - `arrayAssociative`
            - `object`
    - Default value: —
- `extend->objects`

    - Description: Objects or arrays to merge. Moreover, objects can extend arrays and vice versa.
    - Valid values:
        - `array`
        - `stringJsonArray` — as [JSON](https://en.wikipedia.org/wiki/JSON)
        - `stringHjsonArray` — as [HJSON](https://hjson.github.io/)
        - `stringQueryFormatted` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
    - **Required**
- `extend->objects[i]`

    - Description: An object or array containing additional properties to merge in.
    - Valid values:
        - `object`
        - `array`
    - **Required**
- `extend->deep`

    - Description: If true, the merge becomes recursive (aka “deep copy”).
    - Valid values: `boolean`
    - Default value: `true`
- `extend->overwriteWithEmpty`

    - Description: Overwrite fields with empty values.
        The following values are considered to be empty:
        - `''` — an empty string
        - `[]` — an empty array
        - `(object) []` — an empty object
        - `NULL`
    - Valid values: `boolean`
    - Default value: `true`
- `getPropValue`

    - Description: This parameter allows you to return required property of an object.
    - Valid values:
        - `string` — just name of a property or array index / key to return, use as `getPropValue->name` in this case
        - An object of additional parameters:
            - `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
            - `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
            - `stringQueryFormatted` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
            - It can also be set as native PHP object or array (e. g. for calls through `\DDTools\Snippet::runSnippet` or `$modx->runSnippet`):
                - `arrayAssociative`
                - `object`
    - Default value: —
- `getPropValue->name`

    - Description: Object property name or array index / key to return.
        You can also use `'.'` to get nested properties (see `\DDTools\ObjectTools::getPropValue` for more info).
    - Valid values: `string`
    - **Required**
- `getPropValue->notFoundResult`

    - Description: What will be returned when the property is not found.
    - Valid values: `mixed`
    - Default value: `null`
- `outputter`

    - Description: Output format (when result is an object or array).
        Values are case insensitive (the following values are equal: `'stringjsonauto'`, `'stringJsonAuto'`, `'STRINGJSONAUTO'`, etc).
    - Valid values:
        - The snippet can return object as string:
            - `'stringJsonAuto'` — `stringJsonObject` or `stringJsonArray` depends on result object
            - `'stringJsonObject'`
            - `'stringJsonArray'`
            - `'stringQueryFormatted'` — [Query string](https://en.wikipedia.org/wiki/Query_string)
        - The snippet can also return object as a native PHP object or array (it is convenient to call through `\DDTools\Snippet`).
            - `'objectAuto'` — `stdClass` or `array` depends on result object
            - `'objectStdClass'` — `stdClass`
            - `'objectArray'` — `array`
    - Default value: `'stringJsonAuto'`

Examples
--------

[](#examples)

All examples are written using [HJSON](https://hjson.github.io/), but if you want you can use vanilla JSON instead.

### Merge the contents of two or more objects together into the first object (the `extend` parameter)

[](#merge-the-contents-of-two-or-more-objects-together-into-the-first-object-the-extend-parameter)

```
[[ddObjectTools?
	&sourceObject=`{
		cat: mew
		dog: {
			name: Floyd
			weight: 6
		}
		rabbit: 42
	}`
	&extend=`{
		objects: [
			{
				dog: {
					weight: 10
				}
				bird: 0
			}
		]
	}`
]]

```

Returns:

```
{
	"cat": "mew",
	"dog": {
		"name": "Floyd",
		"weight": 10,
	},
	"rabbit": 42,
	"bird": 0
}
```

### Get an object property

[](#get-an-object-property)

```
[[ddObjectTools?
	&sourceObject=`{
		firstName: Chuck
		lastName: Norris
	}`
	&getPropValue=`firstName`
]]

```

Returns: `Chuck`.

#### Custom results when the property is not found

[](#custom-results-when-the-property-is-not-found)

```
[[ddObjectTools?
	&sourceObject=`{
		firstName: Viktor
		lastName: Tsoi
		dates: {
			born: 1962.06.21
		}
	}`
	&getPropValue=`{
		name: dates.death
		notFoundResult: forever alive
	}`
]]

```

Returns: `forever alive`.

### Get an array element

[](#get-an-array-element)

```
[[ddObjectTools?
	&sourceObject=`[
		Pink Floyd
		The Beatles
		Queen
	]`
	&getPropValue=`2`
]]

```

Returns: `Queen`.

### Convert a JSON object to an array

[](#convert-a-json-object-to-an-array)

```
[[ddObjectTools?
	&sourceObject=`{
		firstName: Angus
		lastName: Young
	}`
	&outputter=`jsonArray`
]]

```

Returns:

```
[
	"Angus",
	"Young"
]
```

### Run the snippet through `\DDTools\Snippet::runSnippet` without DB and eval

[](#run-the-snippet-through-ddtoolssnippetrunsnippet-without-db-and-eval)

```
//Include (MODX)EvolutionCMS.libraries.ddTools
require_once(
	$modx->getConfig('base_path') .
	'assets/libs/ddTools/modx.ddtools.class.php'
);

//Run (MODX)EvolutionCMS.snippets.ddObjectTools
\DDTools\Snippet::runSnippet([
	'name' => 'ddObjectTools',
	'params' => [
		'sourceObject' => [
			'cat' => 'mew',
			'dog' => [
				'name' => 'Floyd',
				'weight' => 6,
			],
			'rabbit' => 42,
		],
		'extend' => [
			'objects' => [
				[
					'dog' => [
						'weight' => 11,
					],
					'bird' => 0,
				],
			],
		],
	],
]);
```

Links
-----

[](#links)

- [Home page](https://code.divandesign.ru/modx/ddobjecttools)
- [Telegram chat](https://t.me/dd_code)
- [Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddobjecttools)
- [GitHub](https://github.com/DivanDesign/EvolutionCMS.snippets.ddObjectTools)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance53

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Every ~216 days

Recently: every ~285 days

Total

8

Last Release

704d ago

Major Versions

0.7.0 → 1.0.02024-06-13

PHP version history (2 changes)0.1.0PHP &gt;=5.4.0

0.4.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/09b81986267e62b5fde1473b40aa6f11f7bc26c1c29d5f80f2768c8788e08110?d=identicon)[dd](/maintainers/dd)

---

Top Contributors

[![Ronef](https://avatars.githubusercontent.com/u/1333424?v=4)](https://github.com/Ronef "Ronef (51 commits)")

---

Tags

jsonmodxMODX Evoevoobjectsevolution-cmsmodx evolutionevo cmsevolutioncmsdivandesigndd studiodd groupddobjecttoolsobject toolsmerge jsonmerge objectsextend jsonextend objectsextend arrays

### Embed Badge

![Health badge](/badges/dd-evolutioncms-snippets-ddobjecttools/health.svg)

```
[![Health](https://phpackages.com/badges/dd-evolutioncms-snippets-ddobjecttools/health.svg)](https://phpackages.com/packages/dd-evolutioncms-snippets-ddobjecttools)
```

PHPackages © 2026

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