-
Notifications
You must be signed in to change notification settings - Fork 20
Possible bug with @json
being treated as invalid type
in frame
#142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @dlongley, have you news on this issue? |
@pasquale95 I'm not sure about any required spec changes. However, it would be good to propose some simplified tests in this repo to check the jsonld.js code change works. I assume tests can use inline contexts. If there are variations of the issue, it would be good to add them in case there are other code paths that need a fix. We need the tests so all implementations will have the same behavior. |
@dlongley @davidlehn I don't exactly understand how testing works in this repository, but I've defined a small example in my PR #144. |
@dlongley @davidlehn any update on this PR? |
There's some odd special-case stuff going on here. Because "ex:info" is defined with I first tried the following: {
"@context": {
"ex": "http://example.org/vocab#",
"ex:info": {"@type": "@json"}
},
"ex:info": {
"@value": {},
"@type": "@json"
}
} but that fails, as I described, as it is expanded to However, I got it to work as follows: {
"@context": {
"ex": "http://example.org/vocab#",
"ex:info": {"@type": "@json"}
},
"http://example.org/vocab#info": {
"@value": {},
"@type": "@json"
}
} (it would also work with just No spec changes are necessary, but an informative note to describe how to match JSON literals would be useful. |
@gkellogg if this is not a bug, can you advice me on how should I define the correct frame for this json-ld? {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/vdl/v1"
],
"type": [
"VerifiableCredential",
"Iso18013DriversLicenseCredential"
],
"credentialSubject": {
"id": "did:key:z6MkiiViqftXJKZNnWwpS7aKM7jiJBbGiFEZzPSKYB8p8oyy",
"license": {
"type": "Iso18013DriversLicense",
"document_number": "542426814",
"family_name": "TURNER",
"given_name": "SUSAN",
"portrait": "/9j/4AAQSkZJRgABAQEAkACQA...gcdgck5HtRRSClooooP/2Q==",
"birth_date": "1998-08-28",
"issue_date": "2018-01-15T10:00:00Z",
"expiry_date": "2022-08-27T12:00:00Z",
"issuing_country": "US",
"issuing_authority": "AL",
"driving_privileges": [
{
"codes": [
{
"code": "D"
}
],
"vehicle_category_code": "D",
"issue_date": "2019-01-01",
"expiry_date": "2027-01-01"
},
{
"codes": [
{
"code": "C"
}
],
"vehicle_category_code": "C",
"issue_date": "2019-01-01",
"expiry_date": "2017-01-01"
}
],
"un_distinguishing_sign": "USA"
}
}
} The context I tried with the frame below but it doesn't work: {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/vdl/v1"
],
"type": ["VerifiableCredential", "Iso18013DriversLicenseCredential"],
"credentialSubject": {
"@explicit": true,
"license": {
"type": "Iso18013DriversLicense",
"@explicit": true,
"driving_privileges": {}
}
}
} Any help would be really appreciate. |
In the frame, you’ll need to use some other term expanding to the same IRI for “driving_privilages”; other the full IRI it expands to, itself, or a compact IRI form. The issue is that the frame gets expanded when framing, then it is no longer an empty value, but an expanded JSON value, which prevents it from matching anything. |
I don't understand. The issue is in the fact that Additionally, I don't understand why the |
The key is that the Framing algorithm works by first expanding the frame, which in the original case, results in the following: [
{
"http://example.org/vocab#info": [
{
"@type": "@json",
"@value": {
"@value": {},
"@type": "@json"
}
}
]
}
] To match a value, it would need to exactly match that value object (note the value object, itself, containing |
How did you get that expansion? Unfortunately I don't really understand how to use this example, I prefer using the VDL frame as example since I am able to run and debug it (but I think this doesn't change the situation). {
"@context":[
"https://www.w3.org/2018/credentials/v1",
"https://raw.githubusercontent.com/w3c-ccg/vdl-vocab/main/context/v1.jsonld"
],
"type":[
"VerifiableCredential",
"Iso18013DriversLicense"
],
"credentialSubject":{
"license":{
"type":["Iso18013DriversLicense"],
"driving_privileges":{}
}
}
} The expansion I get is the following: [
{
"https://www.w3.org/2018/credentials#credentialSubject": [
{
"https://w3id.org/vdl#license": [
{
"https://w3id.org/vdl#driving_privileges": [
{
"@type": "@json",
"@value": {}
}
],
"@type": [
"https://w3id.org/vdl#Iso18013DriversLicense"
]
}
]
}
],
"@type": [
"https://www.w3.org/2018/credentials#VerifiableCredential",
"https://w3id.org/vdl#Iso18013DriversLicense"
]
}
] Note that |
I found why you got that value object, the frame is incorrect. We should change it to be: {
"@context": {
"ex": "http://example.org/vocab#",
"ex:info": {"@type": "@json"}
},
"ex:info": {}
} This frame gets expanded as: [
{
"http://example.org/vocab#info": [
{
"@type": "@json",
"@value": {}
}
]
}
] At this point, I still get the issue: jsonld.SyntaxError: Invalid JSON-LD syntax; invalid @type in frame. even if the @value is a wildcard. |
Sorry, comments messed up. If you put the full example in the playground, you can use the Permalink button to capture the state and add to this comment. |
Alright, here the permalink. There's a bug in the framing operation itself and the bug is potentially solved with this PR (unless side-effects which I honestly don't see). |
I see there's the problem you describe with the playground, but I'm not sure it's a spec bug. If you try it in my Ruby distiller, you'll get the following output: {
"@type": [
"https://www.w3.org/2018/credentials#VerifiableCredential",
"https://w3id.org/vdl#Iso18013DriversLicenseCredential"
],
"https://www.w3.org/2018/credentials#credentialSubject": {
"@id": "did:key:z6MkiiViqftXJKZNnWwpS7aKM7jiJBbGiFEZzPSKYB8p8oyy",
"https://w3id.org/vdl#license": {
"@type": "https://w3id.org/vdl#Iso18013DriversLicense",
"https://w3id.org/vdl#document_number": "542426814",
"https://w3id.org/vdl#family_name": "TURNER",
"https://w3id.org/vdl#given_name": "SUSAN",
"https://w3id.org/vdl#portrait": "/9j/4AAQSkZJRgABAQEAkACQA...gcdgck5HtRRSClooooP/2Q==",
"https://w3id.org/vdl#birth_date": "1998-08-28",
"https://w3id.org/vdl#issue_date": {
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2018-01-15T10:00:00Z"
},
"https://w3id.org/vdl#expiry_date": {
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2022-08-27T12:00:00Z"
},
"https://w3id.org/vdl#issuing_country": "US",
"https://w3id.org/vdl#issuing_authority": "AL",
"https://w3id.org/vdl#driving_privileges": {
"@value": [
{
"codes": [
{
"code": "D"
}
],
"vehicle_category_code": "D",
"issue_date": "2019-01-01",
"expiry_date": "2027-01-01"
},
{
"codes": [
{
"code": "C"
}
],
"vehicle_category_code": "C",
"issue_date": "2019-01-01",
"expiry_date": "2017-01-01"
}
],
"@type": "@json"
},
"https://w3id.org/vdl#un_distinguishing_sign": "USA"
}
},
"https://w3id.org/security#proof": {
"@graph": {
"@type": "https://w3id.org/security#BbsBlsSignature2020",
"http://purl.org/dc/terms/created": {
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2022-12-01T12:37:18Z"
},
"https://w3id.org/security#proofPurpose": {
"@id": "https://w3id.org/security#assertionMethod"
},
"https://w3id.org/security#proofValue": "qYbNq0bTdOa+XeHJ8+vQsdFFUOxF2crZMqJsMWvLyy+wLRMm5sNelzoqgJDrFMnfXjZlTy4XBKlOh0rdQtxKRE9VHeH50eYYrXIrcrbsOhYNEyp45kkFpaFgLT5diA71qYzVYhVrzt86NCr5oWHvkg==",
"https://w3id.org/security#verificationMethod": {
"@id": "did:example:489398593#test"
}
}
}
} Perhaps it should be using a term for comparing |
The framing doesn't work since, for how the library is defined, the |
The history of An object (or array) form for (The use of blank nodes Your PR is for the jsonld.js library, and as I mentioned, I think it's an issue with that particular implementation. My implementation in Ruby seems to produce the proper output, and I believe the Framing Algorithm handles this case correctly. Given a difference in the implementations, it may be a good idea to add a minimal test to the Framing test suite, but I'll leave consideration of that to @davidlehn or someone else responsible for jsonld.js. |
Hi, any update since my last comment? |
Hello again, sorry to bother you @gkellogg @davidlehn but I didn't get any news on this front since 2 weeks. |
@pasquale95 Sorry, we're both quite caught up in work on other specifications at the moment, haven't been able to devote more time to your issue. When I checked, it seemed like the distiller was generating output that I would expect, but you may be trying to do something more specific. The distiller link I gave above should have the flags an options set properly to do this. The issue you're having is because using a property in the body of the frame that has So, you're example cited from above would be more like the following: {
"@context": {
"ex": "http://example.org/vocab#",
"ex:info": {"@type": "@json"}
},
"http://example.org/vocab#info": {}
} That would match any value for "http://example.org/vocab#info" and then compact it using "ex:info", if it ends up being a JSON Literal. If you think there's a bug in the distiller, we can take this up at https://github.com/gkellogg/rdf-distiller. So far, it seems that the spec is doing the right thing, although it may not be intuitive, but consider that a limitation of framing with JSON Literals. |
I tried again and to me it looks that the Ruby distiller doesn't handle the JSON literals differently from what JSON-LD Playground does. Even with your suggestion I don't get the correct output. {
"@context":{
"ex":"http://example.org/vocab#",
"ex:info":{
"@type":"@json"
},
"ex:other":{
"@type":"@json"
}
},
"@id":"http://example.org/test/#library",
"@type":"ex:Library",
"ex:info":{
"author":"JOHN",
"pages":200
},
"ex:other":{
"publisher":"JANE"
}
} with either this frame: {
"@context":{
"ex":"http://example.org/vocab#",
"ex:info":{"@type":"@json"},
"ex:other":{"@type":"@json"}
},
"http://example.org/vocab#info":{}
} or this frame: {
"@context": {
"ex": "http://example.org/vocab#",
"ex:info": {"@type": "@json"},
"ex:other": {"@type": "@json"}
},
"ex:info": {}
} The result is always the following: {
"@id": "http://example.org/test/#library",
"@type": "http://example.org/vocab#Library",
"http://example.org/vocab#info": {
"@value": {
"author": "JOHN",
"pages": 200
},
"@type": "@json"
},
"http://example.org/vocab#other": {
"@value": {
"publisher": "JANE"
},
"@type": "@json"
}
} Thus, JSON literals are not handled correctly in both cases. I don't know about Ruby since I'm interested in the JS library, but I would like to know who I should reach out to propose my solution for the JS library. I'm writing on this thread since I thought you were the maintainers of the framing logic inside the |
Using the first frame, it the expanded "info" and "other" IRIs, the playground seems to get the right output: {
"@context": {
"ex": "http://example.org/vocab#",
"ex:info": {
"@type": "@json"
},
"ex:other": {
"@type": "@json"
}
},
"@id": "http://example.org/test/#library",
"@type": "ex:Library",
"ex:info": {
"author": "JOHN",
"pages": 200
},
"ex:other": {
"publisher": "JANE"
}
} The distiller doesn't properly compact to use the compact IRI representations, which I'll need to look at. This would be a compaction issue, not a framing issue. Term selection when compacting is notoriously complicated, but it should work consistently. |
If the spec should be changed as suggested in digitalbazaar/jsonld.js#506, that would be non-editorial. Probably the case for matching JSON Literals is more involved and requires something more than can be described here, also considering issues with expansion and compaction of JSON literals. The main issue is having enough bandwidth in this group to look into things deeply enough. More use cases would be helpful for JSON literals in general when it comes to both framing, expansion and compaction. |
This issue stems from: digitalbazaar/jsonld.js#506
It relates to step 1.3 in the Framing Algorithm where a frame's validity is being checked.
It seems that either that step doesn't appropriately allow for
@json
(which is a valid JSON-LD type) or that the algorithm should have stopped recursing when@json
was detected and just accepted whatever the value was (since it cannot recurse into@json
datatypes, presumably). I didn't look more closely to determine which way to go here with the algorithm (whether it's the former simple fix or not), but I expect that some test cases could help shake it out.The text was updated successfully, but these errors were encountered: