- [Instructor] Sometimes it's not realistic
to change the key names
in JSON data that you want to share.
For instance, if you want to simply provide data
from a large database you maintain,
and you already use a set of key names
that are different
from those in the public context
and type that you want to use.
For this situation,
JSON-LD supports a different type of structure.
Instead of renaming your keys,
you can include an additional object
within your JSON-LD snippet
that maps your key names to the key names used
in the context and type that your snippet references.
I'm going to try this out with the company overview
for h+ Sport.
I have snippet.json open,
which is the data that I want to convert to JSON-LD format.
And so I'm going to select that
and copy it to the clipboard.
And then over in my snippet.jsonld file,
I'll paste that in.
And now I need to convert my content
to use JSON-LD standards.
So I know that the first thing I need to do at the top,
I want to add an @context keyword,
(keyboard clicks)
but instead of simply providing a URL,
this is where I specify the object that maps my keys
to the vocabulary keys.
And so the value here is going to be an opening curly brace.
In my editor,
I can just press enter
and I get a blank line
and the closing curly brace on a new line.
And then after that closing curly brace,
I need to make sure that I include a comma
to keep my format correct.
And I'll save that change.
Now within this sub object on line three,
the first key that I need to add is vocab.
And that's where I'm going to provide the schema.org URL.
So that's going to be @vocab,
and the value again is http://www.schema.org/
and I need to include that final slash after org.
And then a comment at the end of that line.
Next, I need to specify the same keys
that are in my data,
company, website, image, and overview,
and for their values,
I need to provide the corresponding schema.org key name
for each of those pieces of data.
I've already looked these up.
So, I'll start with company and the value is name
and then for website,
(keyboard clicks)
I know my value that I need to use is URL.
Then I have an image key,
and that maps to the logo key for the schema that I'm using.
And finally overview, which corresponds to description.
The object I just created
provides a map between my data below and the keys
at the URL referenced by the @vocab key.
My company key maps to the schema.org name key.
My website key maps to the schema.org URL key, and so on.
I need to add one more piece here.
After the @context object
and before my data starts,
I want to add the at type key
and specify the schema.org type
for this data, which is organization.
So that's before company I'll add at type.
and the value is going to be organization,
and a comma at the end of that line.
And I'll save this,
I'll select it all, and copy it to the clipboard.
And then I'll go to the JSON-LD playground online.
And in the input box, I'm going to paste this.
This checks for basic syntax errors, and I don't have any,
so I'm good.
Using this JSON-LD format lets me take data
that I already have
and indicate how it should be interpreted,
but without needing to redo my own internal systems
for tracking my data.
And that's important,
especially when I want to use the data
for different purposes.
And one set of keys is never going to satisfy
all the different uses.