marl / jams

A JSON Annotated Music Specification for Reproducible MIR Research
ISC License
186 stars 26 forks source link

Enforce consistent sandbox key-value ordering in json serialization? #138

Closed justinsalamon closed 8 years ago

justinsalamon commented 8 years ago

It would be nice if serializing a JAMS object to disk would respect the order in which key-value pairs were added to the sandbox (jams-level and annotation-level), akin to the behavior of an OrderedDict.

Motivation: It's inconvenient that every time a jams object gets serialized to disk the order of the sandbox items gets shuffled - this makes it hard to compare sandboxes (and JAMS files more generally) by visual inspection or using diff tools.

Not sure whether this could be enforced at the JAMS level as well, but would be sweet.

bmcfee commented 8 years ago

I don't think this is possible. Json dictionaries are unordered by definition, so we can't reliably serialize and deserialize while preserving order.

Adding order to the sandbox object is also non trivial, and even doing this in a write only setting would take a lot of custom serialization code.

On Fri, Dec 2, 2016, 22:13 Justin Salamon notifications@github.com wrote:

It would be nice if serializing a JAMS object to disk would respect the order in which key-value pairs were added to the sandbox (jams-level and annotation-level), akin to the behavior of an OrderedDict.

Motivation: It's inconvenient that every time a jams object gets serialized to disk the order of the sandbox items gets shuffled - this makes it hard to compare sandboxes (and JAMS files more generally) by visual inspection or using diff tools.

Not sure whether this could be enforced at the JAMS level as well, but would be sweet.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/marl/jams/issues/138, or mute the thread https://github.com/notifications/unsubscribe-auth/ABIqjMWZPNeQYW5KgTjgF2ISTp1YaN4zks5rEN49gaJpZM4LDLfu .

bmcfee commented 8 years ago

Motivation: It's inconvenient that every time a jams object gets serialized to disk the order of the sandbox items gets shuffled - this makes it hard to compare sandboxes (and JAMS files more generally) by visual inspection or using diff tools.

Following on this: I agree that it would be nice, but it's impossible to enforce using plain-text diff tools. You might want to try using something like json-diff instead of plain diff.

justinsalamon commented 8 years ago

Ok yeah, I imagined it might not be possible but wanted to put it out there just in case.

Cheers for the json-diff tool, will give that a try!