- From: Alexander Surinov <r4seri@gmail.com>
- Date: Mon, 13 Feb 2017 23:33:21 +0300
- To: public-hydra@w3.org
- Message-ID: <CAGjiOLduVarRbrH=VqGjgaq-9xTgk33Jg-NApduHhUp=f_2Row@mail.gmail.com>
Hi everybody, I’m currently try to convert JSON messages from 3rd party APIs to JSON-LD format and keep backward compatibility with clients that uses old JSON structure. For example: Plain JSON object: { "response": { "count": 2, "items": [ { "id": 638865, "first_name": "Emma", "last_name": "Stone" }, { "id": 1053682, "first_name": "Emma", "last_name": "Watson" } ] } } JSON-LD object: { "@context": "/api/contexts/Person", "@id": "/api/friends", "@type": "http://www.w3.org/ns/hydra/core#collection" "response": { "count": 2, "items": [ { "@id": "/api/person/638865", "@type": "http://schema.org/Person" "id": 638865, "first_name": "Emma", "last_name": "Stone" }, { "@id": "/api/person/1053682", "@type": "http://schema.org/Person", "id": 1053682, "first_name": "Emma", "last_name": "Watson" } ] } } As you can see, I just added top level @context, @id and @type to root JSON object and inner JSON objects. These changes will not harm existing clients that uses old JSON structure and they can keep working as before. It’s looks ok. But Image I have the following plain JSON array as top level JSON object. [ { "id": 638865, "first_name": "Emma", "last_name": "Stone" }, { "id": 1053682, "first_name": "Emma", "last_name": "Watson" } ] So, my question is: How can I convert JSON message to JSON-LD format when source JSON message represented as JSON array? As described in JSON-LD specs we can add @context as HTTP Link Header using the http://www.w3.org/ns/json-ld#context link relation. Ok, but where I should define @type and @id for JSON object? -- Best regards, Surinov Alexander
Received on Monday, 13 February 2017 20:36:28 UTC