jmrivas86/django-json-widget

Option to preserve ordering as written

Opened this issue · 0 comments

  • django-json-widget version: 1.1.1
  • Django version: 3.1.x
  • Python version: 3.9
  • Operating System: Mac, Linux

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.