The problem is, on the Python side, the JSON is converted to a plain dictionary, and dictionaries do not necessarily preserve the order of keys. You can ensure the order of keys is preserved in the stored JSON by passing in an OrderedDict rather than a plain dict. However, the DAL will still end up converting to a plain dict when you retrieve the JSON from the field. In CPython 3.6 and all Python 3.7 implementations, I believe dictionaries are supposed to preserve order (though not sure if that applies to json.dumps) -- so, if you are working with Python 3, it might behave as desired without any workarounds. Otherwise, you will probably have to (a) create a custom field type, (b) use a text field type with filter_in and filter_out functions to convert to and from JSON, or (c) store the data in a different format (e.g., a list of 2-tuples).
For more details, see https://stackoverflow.com/a/23820416/440323. Anthony On Thursday, May 31, 2018 at 9:12:05 AM UTC-4, yogeshwar khalkar wrote: > > Hi, > > I have a JSON field in the table with multiple key-value pairs. > > I want to render that data on the screen in the sequence I have entered it. > > But web2py rearranges that data in the database, don't know on which > precedence. > > I want the data in the sequence I have entered in the database. > > Anyone know's what happening here and how to keep the sequence of JSON as > entered. > > Please help me. > > Thanks > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.