Notepad ++宏来转换JSON数组

时间:2019-05-22 03:14:33

标签: json notepad++

在记事本++中对宏不太了解,但是从本质上讲,我想接受此输入:

const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
      .fetch()
      .then(call => console.log(call.from));

并将其转换为:

"BAILIFF": [
    "The prisoners will all stand.",
    "All present, stand and make respectful attention to honouredJudge.",
    "Before this gracious court now appear these prisoners toanswer for the multiple and grievous savageries of their species. Howplead you, criminal?",
    "Criminals keep silence!",
    "You will answer the charges, criminals.",
    "Criminal, you will read the charges to the court.",
    "All present, respectfully stand. Q",
    "This honourable court is adjourned. Stand respectfully. Q"
],
"MCCOY": [
    "Hold it right there, boy.",
    "What about my age?",
    "Troubles me? What's so damned troubling about not having died? How old do you think I am?",
    "Explain how you remember that so exactly.",
    "I don't see any points on your ears, boy, but you sound like aVulcan.",
    "Almost as bad.",
    "They are, they are. And damned annoying at times.",
    "Well, this is a new ship, but she's got the right name. Now youremember that, you hear.",
    "You treat her like a lady, and she'll always bring you home."
],

感谢您的帮助。谢谢。

1 个答案:

答案 0 :(得分:3)

尝试使用此宏:

  1. 记录宏
  2. 控件 + H (搜索并替换)
  3. 搜索内容:^("[^"]+")\s*:\s*\[\s*("[^\n]*?")\s*,(?=\R)|^("[^\n]*?") ("[^"]+")\R\K\h+("[^\n]*?)(?:,(?=\R)|\s*\],?)
  4. 替换为:(?2\2 \1)(?3\5 \4)
  5. 全部替换
  6. 下一个>
  7. 全部替换
  8. 停止录制宏。
  9. 现在使用以下选项播放宏:Run macro multiple timesRun until the end of file