MightyNetwork :: Doc :: JSON-LD (source, CPAN)

CONTENTS

NAME

MightyNetwork::Doc::JSON-LD

DESCRIPTION

JSON-LD (JavaScript Object Notation for Linked Data), is a method of encoding Linked Data using JSON.

It’s JSON, but it can contain reference in addition or instead of the data.

This page will give you only an overview of JSON-LD. Go to https://w3c.github.io/json-ld-syntax/#json-ld-grammar to learn more.

@context

The @context key gives the structure of the data, and their type.

{
    "@context": {
        "id": {
            "@id": "https://my.standard.url/name",
            "@type": "string"
        },
        "name": {
            "@id": "https://my.standard.url/id",
            "@type": "@id"
        }
    },
    "user": {
        "id": 1,
        "name": "Foo"
    }
}

The context can link to an URL that gives the structure.

{
    "@context": {
        "user": "https://my.standard.url"
    },
    "user": {
        "id": 1,
        "name": "Foo"
    }
}

You can avoid using @context by using URL instead of keys.

{
    "user": {
        "https://my.standard.url/id": 1,
        "https://my.standard.url/name": "Foo"
    }
}

data

As seen before, data can be directly in the JSON-LD.

{
    "@context": {
        "user": "https://my.standard.url"
    },
    "user": {
        "id": 1,
        "name": "Foo"
    }
}

But it can also be fetched from an URL.

{
    "@context": {
        "user": "https://my.standard.url"
    },
    "user": "https://my.user.url"
}

Where https://my.user.url will give

{
    "id": 1,
    "name": "Foo"
}

SEE ALSO

MightyNetwork::Doc, MightyNetwork::Doc::JSON-LD-signatures, https://w3c.github.io/json-ld-syntax/