Action

Parse JSON

Posted by posuke, Last update about 1 year ago

JSON Visibility Enhancement Script

Overview:
This script is designed to reformat compressed JSON data into a more readable format. The process clarifies the structure of the data, making the relationships between keys and values easier to understand.

Usage:
1. Apply this action to your compressed JSON data.
2. The formatted JSON will be displayed in a new window.

Steps

  • script

    const selected = editor.getSelectedText();
    let query = '';
    let string = '';
    
    if (!selected || selected.length === 0){
       query = editor.getText();
    }else{
       query = selected;
    }
    
    let items = JSON.parse(query)
    const jsonString = JSON.stringify(items, null, 4);
    let d = new Draft();
    d.content = jsonString;
    d.update();
    app.openInNewWindow(d);
    

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.