Skip to content

Order of JSONAPI data array elements is not preserved #2

@pdrosos

Description

@pdrosos

Hi,

thanks for this normalizer. I would like to use it with my JSONAPI response, but there's a problem with the normalized output - the order of the elements in the JSONAPI data array is not preserved.

I have a JSONAPI response like this:

{
    "jsonapi": {
        "version": "1.0"
    },
    "data": [
        {
            "type": "places",
            "id": 38,
            "attributes": {
                ...
            }
        },
        {
            "type": "places",
            "id": 39,
            "attributes": {
                ...
            }
        },
        {
            "type": "places",
            "id": 11,
            "attributes": {
                ...
            }
        }
    ]
}

which is normalized to this:

{
    "results": {
        "places": [
            11,
            38,
            39
        ]
    },
    "entities": {
        "places": {
            "11": {
                ...
            },
            "38": {
                ...
            },
            "39": {
                ...
            }
        }
    }
}

As you can see, the ids in the JSONAPI response are 38, 39, 11 and in the normalized data are 11, 38, 39. It should not be like that, because the data is ordered by the server and should stay the same in the normalized output.

It will be great if this could be fixed. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions