Search code examples
apisymfonypagination

Override/change name of fields in JSON response in API Platform


I am working on an API Platform 3 (Symfony 6) app.

In my JSON response, I have the following :

{ ... "totalItems": 7065, "itemsPerPage": 10, ... }

Is it possible to change the config so that I get :

{ ... "total_items": 7065, "page_size": 10, ... }

So basically I want to rename these fields, in the response I get. Is it possible ?


Solution

  • The custom normalizer is the solution to this question.

    A custom event listener is also a solution but it is not GraphQL friendly.