2

I've got this json-ld:

{ "@id":   "http://www.example.com/john-doe",
    "@type":   "http://xmlns.com/foaf/0.1/Person",
    "http://xmlns.com/foaf/0.1/name":   "John   Doe",
    "http://xmlns.com/foaf/0.1/age":   {
    "@value":   "42",
    "@kind":   "http://www.w3.org/2001/XMLSchema#nonNegativeInteger"},
    "http://xmlns.com/foaf/0.1/knows" : [
      {   "@id":   "http://www.example.com/charlie-brown"   },
      {   "@id":   "http://www.example.com/jane-doe"   }
    ]
  }

I have to write the context so that the below json-ld is valid.

{ "@context" : "context to write....",
  "@id":   "john-doe",
  "@type":   "person",
  "name":   "John   Doe",
  "age":   "42",
  "knows":   ["charlie-brown", "jane-doe"]
}

I've write a solution but it's incomplete, and I can't figure out how to write a full solution, hope that someone can help me.

  • 1) Do you mean `@type` instead of `@kind`? If not, where is `@kind` coming from? 2) Please share your incomplete solution, if possible. What *exactly* is it that you can’ŧ figure out? 3) Does your second snippet have to work exactly like this, or is it possible to change parts? – unor Feb 11 '18 at 17:04

1 Answers1

2

You have to use framing to get a result close to your requirements.

Use this link for an example in json-ld playground. This is how your document with embedded @context would look like:

{
  "@context": {
    "name": {
      "@id": "http://xmlns.com/foaf/0.1/name"
    },
    "age": {
      "@id": "http://xmlns.com/foaf/0.1/age"
    },
    "knows": {
      "@id": "http://xmlns.com/foaf/0.1/knows",
      "@container": "@set"
    }
  },
 "@id": "john-doe",
 "@type": "person",
  "name": "John   Doe",
  "age": "42",
  "knows": [
    "charlie-brown",
    "jane-doe"
  ]
}

This is, how the frame would look like

{
  "@context": {
    "name": {
      "@id": "http://xmlns.com/foaf/0.1/name"
    },
    "age": {
      "@id": "http://xmlns.com/foaf/0.1/age"
    },
    "knows": {
      "@id": "http://xmlns.com/foaf/0.1/knows",
      "@container": "@set"
    }
  }
}

This will render to

{
  "@context": {
    "name": {
      "@id": "http://xmlns.com/foaf/0.1/name"
    },
    "age": {
      "@id": "http://xmlns.com/foaf/0.1/age"
    },
     "knows": {
      "@id": "http://xmlns.com/foaf/0.1/knows",
      "@container": "@set"
    }
  },
  "@graph": [
    {
      "@id": "john-doe",
      "@type": "https://json-ld.org/playground/person",
      "age": "42",
      "knows": [
        "charlie-brown",
        "jane-doe"
      ],
      "name": "John   Doe"
    }
  ]
}
jschnasse
  • 8,526
  • 6
  • 32
  • 72