-
Notifications
You must be signed in to change notification settings - Fork 23
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
Type Coercion / Node Conversion: @coerce keyword or similar #335
Comments
Related to #386 |
@michaelcpuckett re-reading this issue I understand it's only related to |
@msporny @gkellogg |
Every feature that we add to JSON-LD makes the implementation burden harder for implementers, and understanding the standard harder for developers, which results in worse interoperability and authoring outcomes. Yes, it would be nice if JSON-LD processors did this, but at the same time, this is the first time (that I know of) that this has come up during the 10+ years that JSON-LD has existed. When it comes to things like this, we've suggested that developers first just write a quick function to do some pre-processing on their JSON. For example, a function that runs over a JSON object and turns all "id" values to If we get lots of people clamoring for this sort of type coercion, we can come back and revisit the feature request. Again, the feature is easy to implement... it's getting the standard updated, implementations updated, test suites updated... that's what'll take time. An alternative way to address this is to convince the implementers to provide "pre-processing" functions that they can register w/ the JSON-LD processor. So the processor would always run these pre-processing functions before doing the JSON-LD standard operations. Food for thought. |
I have an idea for a future version of JSON-LD.
As a web developer, I would like to receive a JSON document from i.e. a simple API, add a
@context
to it, and perform JSON-LD operations. This light approach has been a big selling point to me for using JSON-LD.A common response from such an API may include an "id" property as a number (as it is indexed in the source database as an integer), so after applying the
@context
the document may look like this:Currently, the expansion step will generate an error:
Invalid JSON-LD syntax; "@id" value must a string.
My intention in declaring the
@base
was to form the IRI "http://starwars.com/123". I don't think this kind of type coercion is currently possible with JSON-LD.The alternative would be a blank node with a custom ID property, which is less useful in certain situations.
I propose a solution that coerces the XSD type, so that when flattened, it becomes:
As a starting point, I suggest adding a keyword called
@coerce
.I originally opened this as an issue in Framing and got some helpful feedback from @gkellogg:
w3c/json-ld-framing#98
The text was updated successfully, but these errors were encountered: