Nested JSON – Powershell objects not expanding

I came across an issue the other day that took me way too long to figure out. I tried 100 different ways of building nested json but all of them failed to expand the object correctly. I posted to Reddit and a kind user pointed me to a simple fix. The cmdlet ConvertTo-Json has a -Depth parameter. This tells the cmdlet how many levels to go in, I had no idea it defaults to only 2 hence my issues. To replicate this you can run the test code below.

For me this was extremely confusing and stumped me for a good amount of time, hopefully this helps someone out!

0 comments… add one

Leave a Comment