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))
    }

  实现效果

~~~JSON在线格式化 jsoneditor使用_第1张图片

在线DEMO(https://oktools.net/json)

转载于:https://www.cnblogs.com/vivec/p/11275887.html

你可能感兴趣的:(JSON在线格式化 jsoneditor使用)