ConvertTo-Json how to keep an order of the hash table fields

Question:

I am running the following PowerShell code, I need to keep the order of the original hash table keys.

The function returns

Is there any option to keep the order of the original hash table keys?

Answer:

You can create an ordered hash by including [ordered] in front of the @ symbol like this:

Source:

ConvertTo-Json how to keep an order of the hash table fields by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply