How to use the jsonld.promises.flatten function in jsonld

To help you get started, we’ve selected a few jsonld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wikibus / Alcaeus / src / MediaTypeProcessors / RdfProcessor.ts View on Github external
async function flatten (json, url): Promise {
    const opts: FlattenOptions = {}
    if (url) {
        opts.base = url
    }

    const expanded = await jsonld.expand(json, opts)
    const flattened = await jsonld.flatten(expanded, {})

    return flattened[Constants.JsonLd.Graph]
}
github iot-schema-collab / iotschema / tools / gen.js View on Github external
.forEach(name => {
        let str = fs.readFileSync('..' + sep + name, { encoding: 'utf-8' });
        let def = JSON.parse(str);

        jsonld.flatten(def)
            .then(g => {
                g.forEach(n => generate(n));
            })
            .then(() => {
                let actionData = JSON.stringify({ '@context': ctx, '@graph': actions }, null, '\t');
                fs.writeFileSync('..' + sep + 'property-actions.jsonld', actionData, { encoding: 'utf-8' });
                
                let eventData = JSON.stringify({ '@context': ctx, '@graph': events }, null, '\t');
                fs.writeFileSync('..' + sep + 'property-events.jsonld', eventData, { encoding: 'utf-8' });
            });
    });
github iot-schema-collab / iotschema / tools / check.js View on Github external
.forEach(name => {
        let str = fs.readFileSync('..' + sep + name, { encoding: 'utf-8' });
        let def = JSON.parse(str);

        jsonld.flatten(def)
            .then(g => {
                g.forEach(n => check(n, name));
            });
    });