# give/4.16.8.1/src/Framework/FieldsAPI/Concerns/SerializeAsJson.php

GiveWP – Donation Plugin and Fundraising Platform, version 4.16.8.1. 38 lines.

- Page: https://pluginprobe.com/plugins/give/4.16.8.1/code/src/Framework/FieldsAPI/Concerns/SerializeAsJson.php
- Raw: https://pluginprobe.com/plugins/give/4.16.8.1/raw/src/Framework/FieldsAPI/Concerns/SerializeAsJson.php
- Modified: 2022-08-18T18:28:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.16.8.1/code/src/Framework/FieldsAPI/Concerns/SerializeAsJson.php#L10-L20`.

```php
<?php

namespace Give\Framework\FieldsAPI\Concerns;

use JsonSerializable;

trait SerializeAsJson
{

    /**
     * {@inheritdoc}
     *
     * @since 2.22.0 add nodeTye to the json
     */
    public function jsonSerialize(): array
    {
        return array_merge(
        // These values must be serialized for all types
            [
                'nodeType' => $this->getNodeType(),
                'type' => $this->getType(),
                'name' => $this->getName(),
            ],
            // We (recursively) serialize all of the class’ properties and exclude the list provided.
            array_map(
                static function ($value) {
                    if ($value instanceof JsonSerializable) {
                        return $value->jsonSerialize();
                    }

                    return $value;
                },
                get_object_vars($this)
            )
        );
    }
}

```
