Roka
Roka

Reputation: 516

Notepad++ macro to transform JSON array

Not too savvy with macros in notepad++, but essentially I want to take this input:

"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."
],

and transition it to:

"The prisoners will all stand." "BAILIFF"

"All present, stand and make respectful attention to honouredJudge." "BAILIFF"

"Before this gracious court now appear these prisoners toanswer for the multiple and grievous savageries of their species. Howplead you, criminal?" "BAILIFF"

"Criminals keep silence!" "BAILIFF"

"You will answer the charges, criminals." "BAILIFF"

"Criminal, you will read the charges to the court." "BAILIFF"

"All present, respectfully stand. Q" "BAILIFF"

"This honourable court is adjourned. Stand respectfully. Q" "BAILIFF"

"Hold it right there, boy." "MCCOY"

"What about my age?" "MCCOY"

"Troubles me? What's so damned troubling about not having died? How old do you think I am?" "MCCOY"

"Explain how you remember that so exactly." "MCCOY"

"I don't see any points on your ears, boy, but you sound like aVulcan." "MCCOY"

"Almost as bad." "MCCOY"

"They are, they are. And damned annoying at times "MCCOY"

"Well, this is a new ship, but she's got the right name. Now youremember that, you hear." "MCCOY"

"You treat her like a lady, and she'll always bring you home." "MCCOY"

Any help is appreciated. Thanks.

Upvotes: 1

Views: 402

Answers (1)

Julio
Julio

Reputation: 5308

Try with this macro:

  1. Record macro
  2. Control + H (search and replace)
  3. Search what: ^("[^"]+")\s*:\s*\[\s*("[^\n]*?")\s*,(?=\R)|^("[^\n]*?") ("[^"]+")\R\K\h+("[^\n]*?)(?:,(?=\R)|\s*\],?)
  4. Replace by: (?2\2 \1)(?3\5 \4)
  5. Replace all
  6. Next >
  7. Replace all
  8. Stop recording macro.
  9. Now play the macro with the option: Run macro multiple times and Run until the end of file

Upvotes: 3

Related Questions