Closed jeremiahlee closed 10 months ago
@jeremiahlee,
In your node + jsonld test case your input is different from the playground: it does not include @context
in doc
. This is why you see a difference and why name
is dropped. There's no @context
on the input doc
, so name
has no global mapping. The default behavior is to drop name
when that happens. If you'd prefer to get an error instead, you can enable "safe mode" that will throw if anything gets dropped by passing {safe: true}
as an option to functions like compact()
.
@dlongley Thanks, I can confirm that adding the @context
back to the document and sending an empty object {}
as the second parameter to jsonld.compact()
works as expected.
I thought it was quite strange to have to separate out the @context
object from the doc to send to the compact
, but the README example implied that to be the case because there is no @context
on the document.
Working as designed
Properties seem to be removed from the output of
compact
andexpand
unexpectedly. The behavior of the playground and the library differs.Using the example from the README:
If I rename the document property
"http://schema.org/name"
to"name"
so that the full input is:The expanded and compacted output on the Playground are the same if the document property is named
"name"
or"http://schema.org/name"
. This is the behavior I would expect and consider correct.However, using node v18.17.1 and jsonld v8.2.0 of the library produces different output. The
name
property will be missing on output.The console logs a compacted and expanded form with no
name
property.Is there a configuration difference between the Playground and the library? Am I incorrect in expecting the document properties to matched against the property names in the context?