0

I'm trying to get this kind of json body to send it to graph API for a patch.

json {
    "description":  "Something",
    "previewType":  "noPreview",
    "checklist":  
      {
          "18907": 
          {
            "title": "Title 1"
            "isChecked": "True"
          }
      },
      {
          "35669":
          {
            "title": "Title 2"
            "isChecked": "True"
          }
      },
      {
          "41911": 
          {
            "title": "Title 3"
            "isChecked": "True"
          }
      }
}

Here is the code, but I can't get the desired result

$json = @{ 
    description = $sourceTaskDetails.Description;
    previewType = $sourceTaskDetails.previewType;
}

$checklist = @()

foreach($object_properties in $details.checklist.PsObject.Properties)
{
    $checklist+= @{ 
        $object_properties.Name =
        @{      
            title = $object_properties.Value.title;
            isChecked = $object_properties.Value.isChecked;
        }
    }
}       

$taskDetailsPayload.Add("checklist", $checklist)
$jsonTaskDetailsPayload = $taskDetailsPayload | ConvertTo-Json

How do I structure it correctly to get what I shown above, because at this moment instead of title and isChecked I just get the "18907": "System.Collections.Hashtable"

Thanks in advance

Alnedru
  • 2,573
  • 9
  • 50
  • 88
  • 1
    Does this answer your question? [Unexpected ConvertTo-Json results? Answer: it has a default -Depth of 2](https://stackoverflow.com/questions/53583677/unexpected-convertto-json-results-answer-it-has-a-default-depth-of-2) – iRon Feb 04 '20 at 15:27
  • To generally build a PowerShell expression from a Json string to get a an idea of the PowerShell structue, try: `$JsonString | ConvertFrom-Json |` [`ConvertTo-Expression`](https://www.powershellgallery.com/packages/ConvertTo-Expression/3.2.19) – iRon Feb 04 '20 at 16:25

0 Answers0