normalize-json-api icon indicating copy to clipboard operation
normalize-json-api copied to clipboard

Order of JSONAPI data array elements is not preserved

Open pdrosos opened this issue 9 years ago • 0 comments

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!

pdrosos avatar Oct 12 '16 08:10 pdrosos