Parsing a JObject in Powershell

Nandan Hegde 36,146 Reputation points MVP Volunteer Moderator
2022-12-13T07:20:26.827+00:00

I am trying to extract data from REST API whose output and type is as below:
269956-image.png

I want to get the Parent value within the variable $X whose type is JObject.

I tried doing $X.Parent but it is not returning any value.

Is there any basic concept I am missing out here ?

@Andreas Baumgarten @Rich Matheisen

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Aung Zaw Min Thwin 306 Reputation points
    2022-12-14T03:46:37.337+00:00

    Hi,
    You can use ConvertFrom-Json cmdlet to convert json data.
    convertfrom-json

    e.g.

    $JsParent = @'  
        {"type": "AzureKeyVaultSecret", "store": {  
          "referenceName": "AzureKeyValut1",   
          "type": "LinkedServiceReference"  
        }, "secretName": "datasetls"}  
        '@  
          
        $X = New-Object PsObject -Property @{Parent = $JsParent}  
          
        #using pipeline  
        $X.Parent | ConvertFrom-Json  
        #In your case with JObject, pls try below:  
        #$X.Parent.ToString() | ConvertFrom-Json  
      
        #or cmdlet  
        ConvertFrom-Json -InputObject $X.Parent  
        #ConvertFrom-Json -InputObject $X.Parent.ToString()  
    

    or you can refer to this link:
    powershell-accessing-a-jarray-inside-a-jobject

    jObject:
    Methods_T_Newtonsoft_Json_Linq_JObject.htm

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.