CodexBloom - Programming Q&A Platform

PowerShell 7.3 - how to to Parse Nested JSON Response from Azure Function

👀 Views: 86 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-12
PowerShell JSON Azure

I'm not sure how to approach I'm following best practices but This might be a silly question, but Quick question that's been bugging me - I'm experiencing a question while trying to invoke an Azure Function using PowerShell 7.3 and parse the nested JSON response I'm getting. The Azure Function successfully returns a complex JSON structure, but when I try to access nested properties, I get errors or null values. Here's the code I am using to call the function: ```powershell $functionUrl = 'https://myazurefunction.azurewebsites.net/api/myfunction' $response = Invoke-RestMethod -Uri $functionUrl -Method Get ``` The JSON response looks something like this: ```json { "data": { "items": [ { "id": 1, "name": "Item1" }, { "id": 2, "name": "Item2" } ] }, "status": "success" } ``` When I try to access the items like so: ```powershell $items = $response.data.items ``` I get an behavior: `Property 'data' want to be found on this object; make sure it exists and is settable.` I have verified the response by outputting it directly to the console: ```powershell $response | ConvertTo-Json -Depth 10 ``` This shows that the function is returning the expected structure. I've also tried accessing it using `Select-Object`, but I still need to seem to extract the nested items correctly. ```powershell $items = $response | Select-Object -ExpandProperty data | Select-Object -ExpandProperty items ``` This also results in null values. I've checked the content type of the response, and it appears to be `application/json`, so I believe I'm receiving it correctly. Any insights on how to properly parse this nested JSON response would be greatly appreciated. I am trying various methods, but nothing seems to work, and I'm exploring on this scenario. Is there a better approach? I'm working on a web app that needs to handle this. Thanks in advance! This is part of a larger application I'm building. Is there a better approach? This is part of a larger mobile app I'm building. How would you solve this?