How to use json2yaml - 10 common examples

To help you get started, we’ve selected a few json2yaml 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 daptin / daptin / daptinweb / src / components / daptable / DaptableView.vue View on Github external
html: function (item, value) {
//                    console.log("Return function for ", e);
                    const val = YAML.stringify(JSON.parse(value)).replace(/\n/g, "<br>").replace(/\t/g, "  ").replace(/ /g, "&nbsp;")
                    return `<div class="input-cell">${value}</div>`
                  }
                }
github chartshq / datamodel / plugins / markdown.js View on Github external
let namespace = {};

            let parsed = filteredDoclets.map(doclet => parseDoclet(doclet, namespace)).filter(item => item);
            parsed = parsed.reduce((accum, value) => [...accum, ...value], []);

            let documentName = fileName.split('.')[0];
            documentName = documentName[0].toUpperCase() + documentName.slice(1);

            // Create master section to be converted to a YAML file
            const fileDump = {
                title: documentName,
                description: 'Documented Methods',
                sections: parsed,
            };
            // convert to YAML
            const yml = converter.stringify(fileDump);

            // get the path directory path where files will be written
            let destination = config.opts.yaml;
            let temp = fileName.split('-').join('').split('.');
            temp[temp.length - 1] = 'yml';
            let moduleFile = perFileDoclets.filter(doclet => doclet.kind === 'module' ? doclet : null);
            moduleFile.map((file) => {
                if (file.kind === 'module') {
                    temp[0] = file.name;
                }
            });
            let ymlFileName = temp.join('.');
            // If file is memberof a namespace, store it inside the appropriate namespace folder
            // if (namespace.memberof) {
            //     destination = `${destination}${namespace.memberof}`;
            // }
github chartshq / muze / plugins / markdown.js View on Github external
});
        });

        let yamlFiles = fs.readdirSync('./yaml');
        yamlFiles = yamlFiles.map(file => file.toLowerCase());

        for (let obj in segmentObj) {
            const sameLevel = true;
            let objParsed = segmentObj[obj].map(doclet => parseDoclet(doclet, sameLevel)).filter(item => item);
            objParsed = objParsed.reduce((accum, value) => [...accum, ...value], []);
            const fileDump = {
                title: obj,
                description: 'Documented Methods',
                sections: objParsed
            };
            const yml = converter.stringify(fileDump);
            let yamlFileName = `api-${obj}.yml`;
            yamlFileName = yamlFileName.toLowerCase();

            if (!yamlFiles.includes(yamlFileName)) {
                fs.writeFile(`./yaml/${yamlFileName}`, yml, (err) => {
                    if (err) {
                        console.log(err);
                    }
                });
            } else {
                // If a file with the same @segment name is present append data to that file
                fs.readFile(`./yaml/${yamlFileName}`, 'utf-8', (error, content) => {
                    if (error) {
                        throw new Error(error.message);
                    }
                    const data = yaml.parse(content);
github anbuksv / avantation / src / apis / avantation.ts View on Github external
if (server.variables && server.variables.basePath && typeof server.variables.basePath == 'object') {
                server.variables.basePath.default = server.variables.basePath.default.replace(
                    '{basePath}',
                    that.basePath
                );
            }
        });

        if (this.template.components && this.template.components.securitySchemes) {
            for (let security in this.securityHeaders) {
                this.template.components.securitySchemes[security] = this.securityHeaders[security];
            }
        }

        if (this.pipe) {
            console.log(this.json ? JSON.stringify(this.template) : YAML.stringify(this.template));
            return;
        }

        if (this.json || path.extname(this.out) == '.json') {
            if (this.out.endsWith('.yaml')) {
                this.out = this.out.replace('.yaml', '.json');
            }
            let _path = this.out ? path.resolve(this.out) : path.join(process.cwd(), 'openapi.json');
            fs.writeFileSync(_path, JSON.stringify(this.template, null, 4));
            this.afterBuildComplete();
            return;
        }

        fs.writeFileSync(
            this.out ? path.resolve(this.out) : path.join(process.cwd(), 'openapi.yaml'),
            YAML.stringify(this.template)
github Koenkk / zigbee2mqtt.io / docgen / integrating-with-homeassistant.js View on Github external
state_topic: 'zigbee2mqtt/',
        availability_topic: 'zigbee2mqtt/bridge/state',
        ...device.discovery_payload,
    };

    if (payload.command_topic) {
        if (payload.command_topic_prefix) {
            payload.command_topic = `zigbee2mqtt//${payload.command_topic_prefix}/set`;
        } else {
            payload.command_topic = `zigbee2mqtt//set`;
        }
    }

    delete payload.command_topic_prefix;

    let yml = YAML.stringify([payload]);
    yml = yml.replace(/(-) \n {4}/g, '- ');
    yml = yml.replace('---', `${device.type}:`);
    return yml;
};
github Koenkk / zigbee2mqtt / docgen / integrating-with-homeassistant.js View on Github external
state_topic: 'zigbee2mqtt/',
        availability_topic: 'zigbee2mqtt/bridge/state',
        ...device.discovery_payload,
    };

    if (payload.command_topic) {
        if (payload.command_topic_prefix) {
            payload.command_topic = `zigbee2mqtt//${payload.command_topic_prefix}/set`;
        } else {
            payload.command_topic = `zigbee2mqtt//set`;
        }
    }

    delete payload.command_topic_prefix;

    let yml = YAML.stringify([payload]);
    yml = yml.replace(/(-) \n {4}/g, '- ');
    yml = yml.replace('---', `${device.type}:`);
    return yml;
};
github Koenkk / zigbee2mqtt / support / docgen.js View on Github external
state_topic: "zigbee2mqtt/",
        availability_topic: "zigbee2mqtt/bridge/state",
        ...device.discovery_payload,
    };

    if (payload.command_topic) {
        if (payload.command_topic_prefix) {
            payload.command_topic = `zigbee2mqtt//${payload.command_topic_prefix}/set`;
        } else {
            payload.command_topic = `zigbee2mqtt//set`;
        }
    }

    delete payload.command_topic_prefix;

    let yml = YAML.stringify([payload]);
    yml = yml.replace(/(-) \n    /g, '- ');
    yml = yml.replace('---', `${device.type}:`)
    return yml;
}
github Koenkk / zigbee2mqtt.io / docgen / device_page.js View on Github external
delete payload.command_topic_prefix;

    if (!payload.state_topic) {
        delete payload.state_topic;
    }

    if (payload.position_topic) {
        payload.position_topic = 'zigbee2mqtt/';
    }

    if (payload.set_position_topic) {
        payload.set_position_topic = 'zigbee2mqtt//set';
    }

    let yml = YAML.stringify([payload]);
    yml = yml.replace(/(-) \n {4}/g, '- ');
    yml = yml.replace('---', `${device.type}:`);
    return yml;
}
github matthewkeil / nomad-devops / lib / aws / sam.ts View on Github external
export const saveSaml = (template: string) => {
    if (!fs.existsSync(samlDirectory)) {
        fs.mkdirSync(samlDirectory);
    }

    fs.writeFileSync(samlName, require("json2yaml").stringify(JSON.parse(template)));
};
github anbuksv / avantation / src / apis / avantation.ts View on Github external
return;
        }

        if (this.json || path.extname(this.out) == '.json') {
            if (this.out.endsWith('.yaml')) {
                this.out = this.out.replace('.yaml', '.json');
            }
            let _path = this.out ? path.resolve(this.out) : path.join(process.cwd(), 'openapi.json');
            fs.writeFileSync(_path, JSON.stringify(this.template, null, 4));
            this.afterBuildComplete();
            return;
        }

        fs.writeFileSync(
            this.out ? path.resolve(this.out) : path.join(process.cwd(), 'openapi.yaml'),
            YAML.stringify(this.template)
        );
        this.afterBuildComplete();
        return;
    }

json2yaml

A commandline utility to convert JSON to YAML / YML

Apache-2.0
Latest version published 9 years ago

Package Health Score

50 / 100
Full package analysis

Popular json2yaml functions