spdx-spec icon indicating copy to clipboard operation
spdx-spec copied to clipboard

JSON-LD Context fails to compact

Open augelu-tng opened this issue 1 month ago • 4 comments

The spdx-context https://spdx.org/rdf/3.0.1/spdx-context.jsonld fails to compact correctly when being processed with standard json-ld tools such as jsonld-cli. Take for example: spdx-examples/example1.json.

curl -LO https://raw.githubusercontent.com/spdx/spdx-examples/refs/heads/master/software/example1/spdx3.0/example1.json
npm install -g jsonld-cli
jsonld expand example1.json | jsonld compact - -c "https://spdx.org/rdf/3.0.1/spdx-context.jsonld" > example1-expandcompact.json

After expanding and compacting the spdx document we obtain example1-expandcompact.json. This file should be equivalent to the original. However I noticed the following issues:

  • verifiedUsing and externalIdentifier are compacted incorrectly, e.g., verifiedUsing -expand-> https://spdx.org/rdf/3.0.1/terms/Core/verifiedUsing -compact-> spdx:Core/verifiedUsing instead of verifiedUsing.
  • Array values with only one Element get lost, e.g., "rootElement": ["https://swinslow.net/spdx-examples/example1/hello-v3-specv3/SPDXRef-gnrtd4"] -expand-> "https://spdx.org/rdf/3.0.1/terms/Core/rootElement": [{"@id": "https://swinslow.net/spdx-examples/example1/hello-v3-specv3/SPDXRef-gnrtd4"}] -compact-> "rootElement": "https://swinslow.net/spdx-examples/example1/hello-v3-specv3/SPDXRef-gnrtd4".
  • The @id property of CreationInfo elements gets replaced by spdxId property.

The first two issues could be fixed by updating the spdx context, from

"rootElement": {
    "@id": "https://spdx.org/rdf/3.0.1/terms/Core/rootElement",
    "@type": "@vocab"
},
"verifiedUsing": {
    "@id": "https://spdx.org/rdf/3.0.1/terms/Core/verifiedUsing",
    "@type": "@vocab"
}

to

"rootElement": {
    "@id": "https://spdx.org/rdf/3.0.1/terms/Core/rootElement",
    "@type": "@vocab",
    "@container": "@set"
},
"verifiedUsing": {
    "@id": "https://spdx.org/rdf/3.0.1/terms/Core/verifiedUsing",
    "@container": "@set"
}

In general that is:

  • "@container": "@set" should be added to all array properties
  • "@type": "@vocab" should be removed from properties with object values. (I am not sure what the correct @type would be but @vocab seems to be wrong)

For the third issue I don't know how it could be fixed.

augelu-tng avatar Nov 13 '25 11:11 augelu-tng

@zvr - Is this something that can be fixed in the spec parser?

@augelu-tng - Do you think this is a high enough priority for the 3.0.2 release or would fixing this in 3.1 be OK?

goneall avatar Nov 14 '25 22:11 goneall

@goneall as you prefer. From my end, fixing it in 3.1 is totally fine.

augelu-tng avatar Nov 16 '25 16:11 augelu-tng

"@type": "@vocab" should be removed

I also posted thus yesterday: https://github.com/spdx/spdx-3-model/issues/1167 . Should be replaced with "@type": "@id"

VladimirAlexiev avatar Nov 18 '25 02:11 VladimirAlexiev

Joshua thinks that @container: @set wouldn't be too hard. Willing to point at tool for where solution should be applied. We could add test to do compaction and extraction to test equivalence.

kestewart avatar Dec 02 '25 17:12 kestewart