RE: JSON-LD in examples invalid due to comments

On Thursday, November 28, 2013 11:55 AM, Dan Brickley wrote:
> On 28 November 2013 10:45, Markus Lanthaler wrote:
> > Hi,
> >
> > I've just realized that all (?) JSON-LD examples in schema.org are
> > invalid since they include comments. Just as JSON, JSON-LD doesn't
> > support comments.
> >
[...]
> >
> > Would it be possible to remove those comments at the beginning of all
> > examples? I fear that otherwise a lot of people will adapt this style
> > which will lead to severe interoperability problems.
> 
> Fair point, thanks. I took a look around at commenting options for
> JSON-LD recently, and it's pretty bleak. Some people are using
> repeated keys,

That's a more or less well-established JSON practice since JSON parsers *generally* discard all but the last occurrence of a key.


> others using predictably named alternate keys. For
> JSON-LD I'm not aware of an idiom that doesn't give rise to unwanted
> triples, but perhaps there's some hack possible?

It depends on your context. Any key that isn't mapped to an IRI or keyword will be dropped during expansion (expansion is always the first step when processing JSON-LD).

So something like this wouldn't produce any unwanted triples even though I'm using the @vocab "sledgehammer":

{
  "@context": {
    "@vocab": "http://schema.org/",
    "-comment-": null
  },
  "name": "Markus",
  "-comment-": "just a comment"
}


> This does make me wonder about the W3C spec for embedding JSON-LD in
> HTML, http://www.w3.org/TR/2013/PR-json-ld-20131105/#embedding-json-ld-
> in-html-documents
> ... whether it would be wrong, bad and ugly to use HTML's inline
> comment syntax, i.e. <!-- ... -->.

No, unfortunately that wouldn't work. In HTML5 <script> is a raw text element which means that the <!-- --> isn't removed which means that element.innerText will contain those HTML comments as well.


> For the schema.org docs, we should probably just move the comments out
> of the <script>.

Yes, I think that's the simplest and best option especially since the comments don't any value. They just repeat the preceding sentence.


Thanks,
Markus


--
Markus Lanthaler
@markuslanthaler

Received on Thursday, 28 November 2013 11:24:17 UTC