'How to configure Api-platform to return simple JSON instead of JSON-LD?

I'm trying to use refine.dev with Api-platform, but all the responses are in JSON-LD, and I need them as simple JSON.

How can I configure that?



Solution 1:[1]

When you are declaring your collectionOperations or itemOperiation in your entity you can set the needed formats.

collectionOperations: [
        'get ' => [
            'formats' => ['json'],
        ],

You can look at this documentation https://api-platform.com/docs/core/content-negotiation/

Solution 2:[2]

You need to send requests specifying Header Accept: application/json

GET /api/action
Host: example.com
Accept: application/json
Content-Type: application/json
Content-Length: 48 

If you want json to be the default in Swager UI, then you can specify the type globally in the config/packages/api_platform.yaml file

api_platform:
    formats:
        json: ['application/json']

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Harvey Dent