I've recently built a django JSON field, YAML field, Python field to explore ways to store/edit arbitrarily complex hierarchies of data via a CMS.
JSON, YAML, and Python can all be human formatted to be intuitive, but as soon as I coerce the text to python and back, it creates a new object which doesn't have ordering.
Is there a portable data scheme that transparently preserves input order even if the data isn't actually ordered simply to reconstruct the original input however "the humans" decided to build it?
Take for example python/json:
[{
'title': 'First Data Entry!', # intuitive to have certain elements at top
'is_active': True,
'data': 'data here'
'a_list': [1, 2, 3],
},
{
'title': 'Some Data Entry Here!',
'is_active': False,
'data': 'data here'
'a_list': [1, 2, 3],
}]
Or YAML:
I can set up my data in a way that's instantly recognizable to my eye e.g. titles as the first line by convention.
As soon as I parse this into a python object, modify it, and convert it to a YAML/JSON/Python again, I of course no longer have comments or the ordering.
I'm curious if this is a common issue or if this is a wheel I need to invent.
It seems possible with OrderedDict
and writing a serializer (which I've never done...).
My current solution is to use YAML as a raw text field which is readonly - it won't try to write python objects to YAML to preserve style.