-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON: Encoding heterogeneous subobjects #295
Comments
I think this makes sense, but I would recommend being consistent with
Any thoughts on |
I think my preferred approach is to make anything that expects multiple types to have a list of two-element lists (tuples) where the first element is always the type and the second the data: "measures": [
{
"content": [
["clef", {
"line": 2,
"sign": "G"
}],
["sequence", {
"content": [
["event", {
"notes": [
{
"pitch": "C4"
},
{
"pitch": "E4"
},
{
"pitch": "G4"
}
],
"value": "/2"
}],
["event", {
"rest": {},
"value": "/2"
}]
]
}]
]
}
] The reasoning here is that we've found in MusicXML that Elements end up reappearing in many places within the system (accidentals appear on notes/pitches, but also on ornaments such as turns, figured-bass and chord symbols, etc.) and we won't be able to anticipate where an element will appear in the future. So either each element always has a "type" that says what sort of object it is (which leads to redundancy like Or if this is harder for the schema there's some other type of intermediary object which holds type and content only, with all other attributes in a sub-object.
either of these formats have tradeoffs. I think we won't know for sure which is best until we have a toy parser in both an unstructured-object language (Python/Javascript) and a struct-object type environment (C++, etc.) |
for |
In MNX, there are a few places in which an object can contain heterogeneous children objects:
"content"
can contain clefs or sequences."content"
can contain events, grace notes, tuplets, octave shifts and more."content"
can contain stave groups or staves."content"
can contain stave groups or staves.In my initial migration from XML to JSON, I solved this by requiring a
"type"
object that identifies the type of child object. See this example document for an example.This was a pretty fundamental decision, and the pattern is used in various places in MNX, so I wanted to bring this up for discussion. Are there better ways of doing it, or is this OK?
The text was updated successfully, but these errors were encountered: