Friday, 18 August 2017

regex - Prettify JSON in notepad++ without plugins

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.

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...