Search code examples
jsonpowershelllowercase

Powershell ConvertTo-Json keys in lowercase


Running this code

get-service | Select-Object -Property displayname, status, name | convertTo-Json

results for instance in an output like this:

{
    "DisplayName":  "Adobe Acrobat Update Service",
    "Status":  4,
    "Name":  "AdobeARMservice"
},
{
    "DisplayName":  "Adobe Flash Player Update Service",
    "Status":  1,
    "Name":  "AdobeFlashPlayerUpdateSvc"
},

Is it possible to return the keys in lowercase?


Solution

  • You could use calculated properties:

    get-service | Select-Object -Property @{n='displayname';e={$_.displayname.tolower()}}, status, name | convertTo-Json
    

    what this does is changes the way output is formatted

    ps. you could repeat that with all properties pps. https://blogs.technet.microsoft.com/josebda/2014/04/19/powershell-tips-for-building-objects-with-custom-properties-and-special-formatting/