Skip to content
Advertisement

Remove whitespaces, newlines and tabs in json not in json descriptions

I have a json file:

JavaScript

How can I remove whitespaces, newlines and tabs in json, but not in json "message": descriptions like json formatter – minify/compact:

json formatter

using Powershell or Python?

Advertisement

Answer

PowerShell’s ConvertTo-Json cmdlet has a -Compress parameter for this:

JavaScript

Result:

JavaScript

In python you can minify the json by specifying custom separators when calling json.dumps():

JavaScript

Result:

JavaScript
Advertisement