Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minify JSON with PowerShell?

Is there a way to minify (remove all whitespace in this case) a JSON file to turn this

[
    0.000005,
    0,
    0
],
[
    219.740502,
    0.003449,
    4.177065
],
[
    45.210918,
    0.003365,
    -16.008996
],
[
    344.552785,
    0.030213,
    277.614965
],

to this using PowerShell

[0.000005,0,0],[219.740502,0.003449,4.177065],[45.210918,0.003365,-16.008996],[344.552785,0.030213,277.614965],

I have tried several online "minifiers" however the file contains over 100,000 arrays and basically broke all the online minifiers. Any ideas?

like image 772
Gabriel_W Avatar asked Feb 07 '17 05:02

Gabriel_W


1 Answers

Just for your information when you manipulate PowerShell object and convert them to JSON (ConvertTo-Json) you've got the -compress param :

New-Object -TypeName PSCustomObject -Property @{Name="Hugot";GivenName="Victor"} | ConvertTo-Json -Compress

gives :

{"GivenName":"Victor","Name":"Hugot"}
like image 119
JPBlanc Avatar answered Oct 11 '22 21:10

JPBlanc