Skip to content

coercing the type of a nested node in a plain JSON document #267

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

Closed
ghost opened this issue Jun 19, 2013 · 2 comments
Closed

coercing the type of a nested node in a plain JSON document #267

ghost opened this issue Jun 19, 2013 · 2 comments

Comments

@ghost
Copy link

ghost commented Jun 19, 2013

I am processing plain JSON documents of the form:

{
"propertytype1" : {
"key1" : "value1"
}
}

I want to coerce the "@type" of the nested node value, but I don't see an example in the spec nor can I achieve this in the playground.

My attempt at a context is:

"@context" : {
"propertytype1" : {
"@id" : "http://example.org/propertytype1",
"@type" : "http://example.org/PType1"
},
"@vocab" : "http://example.org/"
}

The compact form generated in the playground is:

{
"http://example.org/propertytype1": {
"http://example.org/key1": "value1"
}
}

What I am trying to achieve is:

{
"http://example.org/propertytype1": {
"@type" : "http://example.org/PType1",
"http://example.org/key1": "value1"
}
}

Is it possible to achieve this, if not how do people generally apply contexts to nested JSON documents to get typed node values?

@lanthaler
Copy link
Member

That’s not possible with the current spec. Type coercion in the context only works for values, not for nodes – you have to distinguish between those two.

Currently there’s no way to type a node using just a context. You would need to pre-process the data in order to achieve that. The reason for this design decision is that most of the time, you would end up with invalid data if type coercion would also apply to node objects. I know it doesn’t really solve your problem but does it answer your question?

@ghost
Copy link
Author

ghost commented Jun 19, 2013

Yes, thank you it answers my question, the lack of an example in the spec made me think that was the case.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant