How do I store the contents of an array to a json file in powershell
How do I store the contents of an array to a json file in powershell
I wanted to save the contents of an array to a .json file.The array has some dictionaries in it. I tried
Set-Content -Path 'crl_urls.json' -Value $arrayval -Force
The JSON file has stored System.Collections.Hashtable
. It hasn't stored the values of the dictionaries.
System.Collections.Hashtable
So How do I do it?
2 Answers
2
To correctly save the content in a .json file you should first convert the array to the .json format.
Try this:
ConvertTo-Json -InputObject $arrayval | Out-File -FilePath .crl_urls.json
By using the ConvertTo-Json
cmdlet I was able to export the contents of the array in the JSON file.
Example Code:
ConvertTo-Json
Set-Content -Path 'crl_urls1.json' -Value ($arrayval|ConvertTo-Json) -Force
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment