Add new key value pair to JSON file in powershell.

Question:

I have an existing JSON file with the following:

How do you add new key-value pairs to an existing JSON file? For example, I would like to take the above JSON, and end up with this:

I currently write to JSON with the following code:

Answer:

Convert the JSON data to a PowerShell object, add the new properties, then convert the object back to JSON:

Source:

Add new key value pair to JSON file in powershell. by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply