Reputation: 11
I try to convert JSON
to JSON-LD
and was wondering if I could use JSON-LD
expansion algorithm for creating my converter. Then I could just specify my schema as a context and run the expansion algorithm for doing the conversion. Problem is that I cannot figure out how to define new value objects in context so that the expansion algorithm would work.
Let's say I have this:
{
"timestamp": "2016-01-08T11:01:38Z"
}
and I want to get this:
{
"prefix:time": {"prefix:start": "2016-01-08T11:01:38Z"}
}
I have tried it using the JSON-LD playground with something like this:
{
"@context": {
"timestamp": {
"@id": "prefix:time",
"@value": {"prefix:start": "@value"}
}
},
"timestamp": "2016-01-08T11:01:38Z"
}
But the expanded result looks like this:
[
{
"prefix:time": [
{
"@value": "2016-01-08T11:01:38Z"
}
]
}
]
Is there any way to use the JSON-LD
expansion (or other) algorithm to replace the value with a new JSON
object?
Upvotes: 1
Views: 386
Reputation: 4586
This Jolt transform does the transform you described.
[
{
"operation": "shift",
"spec": {
"timestamp": "prefix:time.prefix:start"
}
}
]
You can try it out at http://jolt-demo.appspot.com/
Upvotes: 1