MNX in JSON example documents and schema #292
Replies: 5 comments 8 replies
-
This looks amazing. It seems like everything from the XML version has been captured and nothing lost! And huge improvement for parsing simplicity! Smaller comments for future:
Fantastic work! |
Beta Was this translation helpful? Give feedback.
-
I had a look at the examples, and while they do look interesting, I think I spotted a few "fundamental" problems with them as expressed. This is not to be a JSON-sceptic, but out of interest to see whether anything is actually gained with a JSON notation format.
This sort of thing will likely give you grief later on:
Putting arbitrary values as keys works fine for parsing, (It's all just strings!) but for data understanding you will likely run into problems since: a) parsers will have to iterate all keys in order to find the content, since they don't know the keys in advance, and I also see that you've converted the data structures in two different ways. One way is "direct" children with a list, e.g.,
but also "indirect" children with the
Is there any pattern you were following for this? In the schema design when did you choose one pattern over the other? (See also my comment below on Myke's suggestion of "sequence"...) I would also be careful with requiring constructs like this, where you specify empty placeholder objects for the number of measures:
since empty objects tend to evaluate as "falsey" in most dynamic languages, so it would be really easy to miscount or discard.
If you make "sequence" an array, will you need to find a place for the attributes you've already defined? In general, where will styling and other attributes go on the "parent" if you convert these things to "direct" children in arrays?
I'm not sure I would call this ugly -- in fact, adding Also, consistency is nice. Knowing that there always is a Out of interest, I took the Multimeasure Rests examples, as it was the largest, in both JSON and XML and saved them as files, in both "raw" and "minified" forms. I also reformatted the JSON example as 2-space indents, per Myke's comment. Here's what I found:
This would suggest that in fully expanded form, the JSON is 2.6x larger than the XML example, and with 2-space indents still ~2x larger than the XML. Minifying them by removing whitespace gives a slight edge to JSON. (The actual byte size is 2608 for the minified JSON, and 2653 for the minified XML, so a saving of 45 bytes for JSON). |
Beta Was this translation helpful? Give feedback.
-
Thanks for providing the experimental schema. I've been experimenting generating MNX JSON using C++ with the nlohmann/json library and validating against this schema. But there a minor gremlin in the schema: syntax error line 173 spurious trailing comma. |
Beta Was this translation helpful? Give feedback.
-
Very interesting developments here! I have been working on other non musical projects but it’s exciting to see this new (old?) initiative coming to life. I think I originally disliked the JSON idea back in the day but I think it’s very much worth considering now. I will make just one comment concerning examples, because the proof of the relative advantages of this approach is going to come out of actually trying it. (I am sure that all the problems of migrating the music modeling to JSON are solvable — the real issues are around practicality, utility, community acceptance.) For a real validation, my suggestion is: write some kind of toy renderer or even (dare I say it) toy editor for a subset of the proposed JSON version of MNX. No under the hood transformations to MusicXML allowed. How does it feel to write it? Some wag better not suggest I do it (it will only validate my inability to code any more). |
Beta Was this translation helpful? Give feedback.
-
Once again I would love to see the development include a spec document (I think you plan to use JSON Schema, Structural OpenAPI is also an option). With a spec document we can be doing code generation in other languages. We could even check-in code generating programs, a make file, and validation tests. All of this is unlocked by a machine-friendly specification language! |
Beta Was this translation helpful? Give feedback.
-
As the next step in exploring the idea of moving to JSON, I've done the following:
My goals were:
In doing this, I took a first stab at porting our existing XML elements to a JSON structure. I put some thought into this but not a lot; I expect some of the decisions I made won't stand up to scrutiny and that there's a better way to organize the data.
I realize many people will be tempted to dive into the weeds and make suggestions on better ways to encode things. Please avoid that temptation — those sorts of decisions will come a bit later! I'm looking for higher-level feedback, specifically the following:
My own take is that this feels good. Nice and compact, with just as much expressiveness as we've had in XML. The main ugliness is the need to encode a
"type"
for a few of the objects, in situations where we have an array of heterogeneous items (e.g., sequence content and measure content).I'd never used JSON Schema before and was pleasantly surprised at how clear and easy it was to get started with it. In my estimation it supports all of the things we need to do. The trickiest bit I ran into so far is encoding the ability for an array to contain heterogeneous items; I'm not sure whether I've encoded this in the right way, but it seems some combination of
"anyOf"
or"allOf"
will get the job done.Without further ado, here are the experiments:
If feedback here is positive, I think that'll seal the deal for using JSON, and we can commit to the change. The next step would be to put more thought into the details of encoding the various bits of the document, using my experiment as a starting point. I'll also need to change our docs system to support JSON, but I don't expect that'll be too much work.
Beta Was this translation helpful? Give feedback.
All reactions