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

  实现效果

~~~

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM