jmrivas86 / django-json-widget

An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)
MIT License
440 stars 88 forks source link

Option to preserve ordering as written #58

Open shacker opened 3 years ago

shacker commented 3 years ago

Description

Expected: Order of object keys is preserved as written

What actually happens: On save, django-json-widget re-orders the keys in the top-level dictionary and in sub-dictionaries arbitrarily. I know that the order of contents of python dictionaries was not guaranteed in the past, but on later versions of python it is, and I am running a version of python that should preserve dictionary ordering. Oh, but this is JSON, not Python, and I see that JSON objects still do not guarantee ordering.

Is there any way to prevent this for some models where it's undesirable? In my use case, I'm rendering Swagger (OAS) docs with Redoc and I want to control the order of endpoints listed in the UI. Redoc says "We preserve the order in which they're presented" but I can't control that because this widget re-orders them on save.