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: @
Answer from @ForbesLindsay on GitHub (thanks!)—
produces
The problem you're having is that
xml2jsondoesn'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.