PowerShell 7.3 - How to Successfully Retrieve and Parse Nested JSON Objects from a REST API Response?
After trying multiple solutions online, I still can't figure this out... Quick question that's been bugging me - I'm trying to call a REST API that returns a nested JSON response, and I'm having trouble parsing the data correctly in PowerShell 7.3. The API returns the following JSON structure: ```json { "data": { "items": [ { "id": 1, "name": "Item1", "details": { "description": "Description1", "price": 10.5 } }, { "id": 2, "name": "Item2", "details": { "description": "Description2", "price": 15.0 } } ] } } ``` When I run my PowerShell script, I can retrieve the data, but I need to seem to access the nested properties properly. Hereβs the code Iβm currently using: ```powershell $response = Invoke-RestMethod -Uri 'https://api.example.com/items' -Method Get foreach ($item in $response.data.items) { Write-Output "ID: $($item.id), Name: $($item.name), Description: $($item.details.description), Price: $($item.details.price)" } ``` However, I get the following behavior when trying to access `$item.details.description`: ``` want to index into a null array. ``` Iβve tried checking if `$response.data.items` contains any items before the loop, and it does. The scenario seems to be specifically with accessing the nested `details` object. I also validated that the JSON is correct using an external tool. What am I missing? Is there a best practice for handling such nested JSON structures in PowerShell? Any help would be greatly appreciated! This is part of a larger CLI tool I'm building. Could someone point me to the right documentation? The project is a CLI tool built with Powershell. I'd be grateful for any help.