JSON and XML shortcomings
{ "@type": "http://schema.org/Article", "identifier": "5Pl8d4" "author": "Author name", "datePublished": "2020-1-1", "image": { "@type": "http://schema.org/imageObject", "url": "http://example.com/image.png", "height": 600, "width": 800 }, "publisher": { "@type": "http://schema.org/Organization", "name": "Publisher name", "logo": { "@type": "http://schema.org/imageObject", "url": "http://example.com/logo.png" } } }
<http://schema.org/Article identifier='5Pl8d4' { author= "Author name" datePublished= "2020-1-1" image= <http://schema.org/imageObject { url= "http://example.com/image.png" height=600 width=800 }> <#"String properties can also be defined in attributes"> publisher= <http://schema.org/Organization name='Publisher name' { logo=<http://schema.org/imageObject url='http://example.com/logo.png'> }> }>
JSON-LD is today one of the best languages for serializing a typed objects graph. But the inability to name objects in JSON has two flaws:
- The absence of named headers enriched with attributes prevents an efficient event-driven parsing. Typed objects can not be directly instantiated and an intermediate generic objects tree is needed.
- The
@type
property affects readability.
On the other hand, XML lacks a key-node pair structure and is not well suited for this purpose.
GS solves these problems by combining JSON object properties and XML named object features.
GS-graph language
GS-graph is a secure library for building and serializing complex and recursive graphs of typed objects. At parsing stage, according to its configuration, typed objects are instantiated, properties are assigned and explicitly authorized methods can be called.
<?graph> <User account=2197 %id=JOM { name= "John Merting" chief= <%ref "MAD"> groups= [ <%ref "MGRS"> ] }> <User account=2123 %id=MAD { name= "Marc Dublof" groups=[ <Group id=36564 %id=admins { name= "Administrators" }> ] addTemporaryDelegation = <%call [ <%ref "JOM"> <Date day='2019-12-22'> 14 ]> }> <Group id=35 %id=MGRS{ name= "Managers" }>
GS-graph uses the GS attribute and node special type %
instruction to link objects and call methods at the building stage.
A first experimental GS-graph building implementation is available in Typescript and Javascript. Source code is available at https://github.com/generic-syntax/gs-js.