2

I use pug to write .json files (compiled with gulp, gulp-pug and gulp-xml2json).

It works really well normally, but I can't figure out how to get it to handle the asperands (@) necessary for json-ld structured data. I've tried every type of interpolation I can think of, including the method suggested by the author for a similar problem (see issue #2783 on github), but haven't had any luck.

Is there a simple solution I'm overlooking?

This works

// data.json.xml.pug   

root
  context https://json-ld.org/contexts/person.jsonld

compiles to

// data.json

{
  "context": "https://json-ld.org/contexts/person.jsonld"
}

This doesn't

// data.json.xml.pug   

root
  @context https://json-ld.org/contexts/person.jsonld

unexpected text "@cont"

This doesn't either

// data.json.xml.pug   

root
  #{'@context'} https://json-ld.org/contexts/person.jsonld

Error: Error: Unencoded <

...

Char: @

0

1 Answer 1

3

Answer from @ForbesLindsay on GitHub (thanks!)—

#{'@context'}

produces

<@context></@context>

The problem you're having is that xml2json doesn't interpret that as valid xml (because it isn't) you will need to find out if there is any valid xml string that produces your desired JSON, then you can figure out how to generate that XML in pug.

Not the answer you're looking for? Browse other questions tagged or ask your own question.