[oslc-core] [oslc-cm] Problem with OSLC v1 style JSON representations

Patrick Streule patrick_streule at ch.ibm.com
Thu Mar 4 06:00:36 EST 2010


Hi Dave,

>    nicejson = "({\"foo\" \: \"bar\"})";
>    niceobject = eval(nicejson);
>    document.write("<p>niceobject.foo=" + niceobject.foo + "</p>");

I agree that this nice, but allowing this in general would impose JS
language restrictions on property names. Not only the prefix notation is
problematic, also fully qualified identifiers like
'com.example.properties.foo' would not work, and there may also be
conflicts with reserved words in JS.

>    // colons in JSON field names does not work (prefixed property
isundefined)
>    annoyingjson = "({\"prefix:foo\" \: \"bar\"})";
>    annoyingobject = eval(annoyingjson);
>    document.write("<p>annoyingobject.prefix:foo=" + annoyingobject.foo
> + "</p>");

You would write
   document.write("<p>annoyingobject.prefix:foo=" + annoyingobject
["prefix:foo"] + "</p>");

This is only slightly longer than the dot notation.

>    // two properties with same name does not work (eval will fail)
>    annoyingjson2 = "({\"foo\" \: \"bar\", \"foo\" \: \"baz\"})";
>    annoyingobject2 = eval(annoyingjson2);
>    document.write("<p>annoyingobject1.foo=" + annoyingobject1.foo +
"</p>");

IMO, we should leverage JSON's support for arrays here, and not try to
translate an XML or RDF representation too literally to JSON. So the
example would be:

   annoyingjson2 = "({\"foo\" : [\"bar\", \"baz\"]})";
   annoyingobject2 = eval(annoyingjson2);
   document.write("<p>annoyingobject1.foo=" + annoyingobject1.foo +
"</p>");
   for (var i= 0; i < annoyingobject1.foo.length; i++) {
       document.write(annoyingobject1.foo[i]);
   }

Regards,
Patrick





More information about the Oslc-Core mailing list