MNX in JSON discussion #291
Replies: 10 comments 45 replies
-
Responding to @ahankinson's comment from here:
I think JSON offers a better story here. For the example of a note's accidental, a note struct could support either a string or an object, like this: // Simple version
{
"pitch": "G#4",
"accidental": "sharp"
}
// Extended version
{
"pitch": "G#4",
"accidental": {
"value": "sharp",
"color": "red"
}
} Parsing this would be relatively simple. In pseudocode: if typeof note['accidental'] is string:
value = note['accidental']
else:
value = note['accidental']['value'] This is what I meant by "upgrading" simple attributes in the advantage number 8 of my original post. In contrast, "upgrading" XML attributes to child elements (as you've described in MEI) feels more complicated and less natural, because an attribute is a completely different animal than a child element. Accessing an XML element's attribute has an entirely different API than accessing a child element. |
Beta Was this translation helpful? Give feedback.
-
Meta discussion: Can I close and lock #290 so discussion stays in one place? |
Beta Was this translation helpful? Give feedback.
-
Considering what can be done with one and not with the other, there is plenty of XSLT tools and native browser support for XSLT. This would still allow to transform MusicXML to MNX, but not the other way around. I'm not sure about the other pros and cons. E.g. XQuery and XPath without XSLT loses half the use cases. I can't find advantages of JSON that would be impossible in XML except perhaps the upgrades mentioned at 8. What's problematic on transforms in general is the scope. There is so many elements and attributes. A good structure of the schema with several sub-schemas would allow to differentiate the basic and less frequently used extras. To achieve this, XML schema nesting works better than JSON schema nesting, at least the last time I worked with it. This would be a little advantage of XML. |
Beta Was this translation helpful? Give feedback.
-
(I didn't want to turn this into a format war, but now it's a discussion I feel a bit less guilty about mentioning my personal favourite 😉) I think MNX should consider using StrictYAML.
StrictYAML discards all the bloat from ordinary YAML so you're just left with objects, arrays, and string values. It's like JSON but a lot prettier and much easier to edit by hand.
Unlike JSON, StrictYAML supports comments and preserves key order in objects during a roundtrip. Sadly StrictYAML only has one implementation and it's in Python. However, it is a subset of ordinary YAML so you can use any YAML parser and simply avoid using any features except for objects, arrays, and string values. |
Beta Was this translation helpful? Give feedback.
-
Raising it here in a new thread. But I will point out that JSON has JSON Schema which I imagine any standardization effort would need to adopt. A format that cannot be validated somehow isn't a great format. |
Beta Was this translation helpful? Give feedback.
-
The current MNX documentation makes use pseudocode to define parsing of micro-syntaxes, e.g. the Chromatic pitch data type. Making the MNX JSON schema a formal part of the specification would greatly reduce the need for such pseudocode. The micro-syntax of strings can be defined in the schema by regular expressions. E.g. "pattern": "^A-G[0-9]+([+-][0-9./]+[ow]?)?$" or some such. The text can then concentrate on the semantics of the string, whereas the syntax is defined formally by the schema, not by pseudocode. I would very much like to see the schema developed hand in hand with the descriptive specification, and not something that is left until the end, - q.v. continuous integration. |
Beta Was this translation helpful? Give feedback.
-
I've been reflecting on the various feedback, and here's a general observation/question: for the people who prefer XML over JSON, how much of that preference is tied to your usage of static typing? Personally I use dynamically typed languages — primarily Python and JavaScript — so I'm completely comfortable with the idea that a data format would itself be dynamic. By this, I mean I'm happy to parse it without requiring a formal schema, and philosophically I'm completely OK with not knowing types of things until the last possible moment. I'm also deeply influenced by Postel's law: "be liberal in what you accept." For those of you who primarily use Java, C++, etc., does something about JSON's dynamic nature clash with your approach to programming? I personally have never used a formal schema when parsing XML or JSON, across two decades of being a professional software developer, but the various comments here have opened my eyes to other developers' desire for formal schemas. I have a hunch this is a sort of fundamental difference in attitude, which may be correlated with strong typing, and I'd like to understand it more. To make this general point in another way: I'm wondering how much of the anti-JSON pushback represents a larger cultural difference (static vs. dynamic) more than anything else. |
Beta Was this translation helpful? Give feedback.
-
I was happy to see that the co-chairs still consider the issue open. I'm wondering if it would be amenable to the co-chairs if we explored some friendly parallel development of MNX in both XML and JSON formats. I don't mean committing to both XML and JSON as alternative formats (though that's always a possibility). More concretely, I'm wondering if I might have the blessing of the co-chairs to contribute my XML (and music) expertise toward the continued development/maintenance of MNX in XML format. I had shown interest a couple years ago (MNX having the distinction of being the topic of my last tweet 😁). And @adrianholovaty replied with a friendly invitation to get involved. But I had not followed up in earnest until now, after it might be too late! I bring this up for three immediate reasons, all related:
What are people's thoughts on the overall idea? Does it make sense to welcome my involvement in this way? If so, how can I contribute? There's nothing like the potential loss of something I loved to motivate me to do so. Thanks for your consideration. |
Beta Was this translation helpful? Give feedback.
-
As a light relief, I found this looking for views on JSON. It's somewhat tongue-in-cheek, and a little out of date, but looking past the humour and sarcasm there are some interesting comments on JSON in here. JSON Considered Harmful |
Beta Was this translation helpful? Give feedback.
-
Closing this, as the JSON decision has been made. Thanks to all for the thoughts! |
Beta Was this translation helpful? Give feedback.
-
Here's a discussion topic for issue #290 — whether to change MNX to use JSON. Let's try to have a conversation here, as it's a bit more manageable than a normal GitHub issue, thanks to the threading features.
Beta Was this translation helpful? Give feedback.
All reactions