# Transform entity/array of entities to JSON

**URL:** <https://forum.mautic.org/t/transform-entity-array-of-entities-to-json/23060>\
**Category:** Development\
**Created:** [March 15, 2022, 3:19pm UTC](https://forum.mautic.org/t/transform-entity-array-of-entities-to-json/23060 "2022-03-15T15:19:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [March 15, 2022, 3:19pm UTC](https://forum.mautic.org/t/transform-entity-array-of-entities-to-json/23060/1 "2022-03-15T15:19:43Z")

</div>

Hi,

I have an array of entities (Doctrine objects) and I would like to transform it to JSON by leveraging Mautic loadApiMetada and serialization mechanism that is already provided by Mautic core so I can avoid manually composing the JSON.

Does anyone have any directions for me (has done this before) and knows what combination of services and method I need to use to get his?

Thanks.  
Regards, M.

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [March 15, 2022, 9:40pm UTC](https://forum.mautic.org/t/transform-entity-array-of-entities-to-json/23060/2 "2022-03-15T21:40:08Z")

</div>

Update:

I am able to serialize the data using the follwoing line:

```auto
$this->webhookModel->serializeData($records);

```

The thing is that I would like to exclude some fields as they are not relevant for my situation. And I know this is possible to do because api response returns response without those fields.

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [March 15, 2022, 10:01pm UTC](https://forum.mautic.org/t/transform-entity-array-of-entities-to-json/23060/3 "2022-03-15T22:01:22Z")

</div>

I solved it by using:

```auto
use Mautic\ApiBundle\Serializer\Exclusion\FieldExclusionStrategy;
$this->webhookModel->serializeData($records, null, [
            new FieldExclusionStrategy([
                'Changes',
                'PastChanges'
            ], 0)
        ]);

```

I simply excluded the fields I did not want in JSON.
