Action

JSON → TSV

Posted by Jørgen Arnor G. Lom, Last update 17 days ago

Steps

  • script

    const selected = editor.getSelectedText();
    let query = '';
    let string = '';
    
    if (!selected || selected.length === 0){
       query = editor.getText();
    }else{
       query = selected;
    }
    
    const items = JSON.parse(query);
    const replacer = (key, value) => value === null ? '' : value;
    const header = Object.keys(items[0]);
    const csv = [
      header.join('\t'), // header row first
      ...items.map(row => header.map(fieldName => JSON.stringify(row[fieldName], replacer)).join('\t'))
    ].join('\r\n')
    
    string = csv;
    
    if (!selected || selected.length === 0){
    	editor.setText(string);
    }else{
    	editor.setSelectedText(string);
    }
  • clipboard

    template
    [[draft]]

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.