JSON在线格式化,jsoneditor使用

    const placeholder = {
        string: 'hello world!',
        boolean: true,
        color: '#6c928c',
        number: 123,
        null: null,
        array: [1, 2, 3],
        object: {a: 'b', c: 'd', e: 'f'}
    };
    const json_editor = new JSONEditor(document.getElementById("json_editor"), {mode: 'code'}, placeholder);
    const tree_editor = new JSONEditor(document.getElementById("tree_editor"), null, placeholder);
    tree_editor.expandAll();

    function toTree() {
        tree_editor.set(JSON.parse(json_editor.getText()));
        tree_editor.expandAll();
    }

    function toJson() {
        json_editor.setText(JSON.stringify(tree_editor.get(), null, 2))
    }

实现效果

image.png

在线DEMOhttps://oktools.net/json

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容