3

I'm trying to prettify a JSON object in Notepad++. The first solution that comes to mind is using a dedicated plugin. The thing is that the computer I'm working on is not connected to the Internet and all I can use is Notepad++ and all the functionalities Windows 10 offers.

Let's say this is the JSON object

'ugly' version:

{"_class":"value_to_be_ignored","first_key":{"second_key":{"user_id":"123456","company_id":"9876","question":{"subject":"some_subject","case_type":"urgent","from_date":{"year":2011,"month":11,"day":11},"to_date":{"year":2012,"month":12,"day":12}},"third_key":[{"role":"driver","weather":"great"},{"role":"father","weather":"rainy"}]}}}

and 'pretty' version I would like to get as the result:

{
  "_class": "value_to_be_ignored",
  "first_key": {
    "second_key": {
      "user_id": "123456",
      "company_id": "9876",
      "question": {
        "subject": "some_subject",
        "case_type": "urgent",
        "from_date": {
          "year": 2011,
          "month": 11,
          "day": 11
        },
        "to_date": {
          "year": 2012,
          "month": 12,
          "day": 12
        }
      },
      "third_key": [
        {
          "role": "driver",
          "weather": "great"
        },
        {
          "role": "father",
          "weather": "rainy"
        }
      ]
    }
  }
}

I know that it is feasible to enter Enter + Tab combination while going through the file manually. The target file is quite large so I want to automate the process.

I know that I can use regex. The following example creates new line - it's helpful but doesn't solve my problem fully. The problem is that I don't know to handle tabulation and closing parentheses:

enter image description here

I wonder whether it's possible to come up with a pair of RegExes for Find what: and Replace with: that gets us from the ugly version to the pretty version.

balkon16
  • 1,338
  • 4
  • 20
  • 40
  • No, this is balanced text `{}` of `[]` that needs a loop and a stack to do the indentation. Not going to work with NP++ alone. If you use Perl I'll show you how to do it. –  May 07 '19 at 15:59
  • 1
    Perhaps you could download the plugin with another computer and copy it to the PC without internet. Many text-manipulation things that seem impossible can be achieved with notepad++ with regexes and macros, But i think this task won't fit here. – Julio May 08 '19 at 13:26
  • 1
    [This answer](https://stackoverflow.com/a/5083037/983430) should tell you what you're after, including which DLL file to copy where for offline installation. – Amos M. Carpenter Jul 02 '19 at 00:47

0 Answers0