hluk / copyq-commands

Useful commands for CopyQ clipboard manager.
331 stars 73 forks source link

Proposal: Paste formatted Json #10

Closed PhiLhoSoft closed 6 years ago

PhiLhoSoft commented 6 years ago

Web developers often handle unformatted Json data, all in one line. Often hard to read, when the amount of data increases. In the past, I wrote a Lua script for SciTE to format Json. With CopyQ, the task is trivial. Code:

[Command]
Name=Paste formatted Json
Command="
    copyq:
    var text = str(input())
    try {
      var json = JSON.parse(text)
      // Remplace '\\t' with a number to indent
      // with this amount of spaces
      text = JSON.stringify(json, null, '\\t')
    } catch (e) {
    }
    copy(text)
    paste()
    "
Input=text/plain
InMenu=true
HideWindow=true
Icon=\xf121

Description: Pastes selected Json text as a formatted Json text. If not Json, just pastes the text as is.

hluk commented 6 years ago

Nice idea. Can you create pull request for this?

hluk commented 6 years ago

Thanks for the PR.