marshmallow-jsonapi
marshmallow-jsonapi copied to clipboard
Ordering JSON data
I am not sure why but attributes come first instead of id and type, example
"data": [
{
"attributes": {
"Birthday": "1986-08-11",
"address": "ASAP",
"creation_date": "2015-09-22T18:03:20.950821+00:00",
"email": "[email protected]",
"is_active": true,
"mobile": 98765544,
"name": "Leo",
"website": "http://leog.in"
},
"id": "1",
"type": "users"
},
Python dictionaries are unordered. I suppose we could use a OrderedDict
by default, or perhaps if the ordered
class Meta option is set. I may look into this within the next week or two; PRs always welcome. =)
This would be a bit of an odd feature. JSON objects are inherently unordered... I guess this is just so stuff looks better to humans for display?
I guess this is just so stuff looks better to humans for display?
Correct; renderers may want to respect order (l believe DRF's browse-able API does this). Given that marshmallow has and ordered
option, I think this feature makes sense.
@Leo-G See https://marshmallow.readthedocs.io/en/latest/quickstart.html#ordering-output.
Thought this was working but it is not, we need to pass ordered
argument to SchemaOpts
. I can work on a pull request when the marshmallow 3.0 changes are finalized.