Serialising to JSON

At the web conference, some people remarked on serialising to JSON. I know 
that Norm has that as an option, though I haven't yet looked at the format 
he produces. I think we ought to think about how we believe it should be 
done, so that we can agree on a standard representation.


In my 2017 paper at XML Prague 
(https://cwi.nl/~steven/Talks/2017/02-11-prague/descriptions.html), I said


In the true spirit of "data wants to be format neutral", there is strictly 
speaking no reason why the parse tree need be in XML, but could be equally 
well serialised in some other form, such as JSON. Taking an example like 
this:
<expr>
     <prod>
         <letter>a</letter>
         <sum>
             <digit>3</digit>
             <letter>b</letter>
         </sum>
     </prod>
</expr>

you might be tempted to try to express this as:

{"expr":
     {"prod": 
         {"letter": "a"; 
          "sum": {"digit":"3"; "letter":"b"}
         }
     }
}

However, JSON object members are more like XML attributes than child 
elements, because they are not ordered, and (probably) member names may not 
be duplicated.

So you have to use arrays to ensure that element substitutes are ordered, 
but maybe, since JSON object members are like attributes, attributes could 
be placed in those.


I recognise that there is a typing issue that doesn't arise in XML though, 
"digit": 3 vs "digit": "3".


Steven

Received on Tuesday, 9 May 2023 12:17:48 UTC