INVALID_JSON_ATTRIBUTE Error in powershell

Hi All

I am trying to write a Hash table for the below JSON code in power shell script and getting INVALID_JSON_ATTRIBUTE error
Example JSON CODE
"actions" : [ {
     "action" : "CONN_POOL_STATS",
     "resources" : [ {
       "cluster" : true
     } ]
   }, {
     "action" : "COLL_STATS",
     "resources" : [ {
       "collection" : "",
       "db" : "staging"
     } ]
   } ]
Here is the Hash table i tried for the above JSON code and assigned it to a variable newrole and using Convertto-JSON at the end.
$newrole = @{
actions = @(
               @{
               action = 'CONN_POOL_STATS'
                resources = @(
                              @{
                cluster = "true"
                               }   
                              )
                 }
                @{
              action = 'COLL_STATS'
               resources = @(
                             @{
                collection = ''
                db = 'staging'
                              } 
                            )
                 }
           )
$newrole2 = $newrole | ConvertTo-Json
Here is the Error while executing powershell script. Can anyone please help me identify the error with hash table code Invoke-RestMethod : {"detail":"Received JSON for the actions attribute does not match expected format.","error":400,"errorCode":"INVALID_JSON_ATTRIBUTE","parameters":["actions"],"reason":"Bad Request"}

Hello pk30,

You need to add coma on line #11.

You need to increase Depth parameter of ConvertTo-Json. Default value is 2 and it is too small for you nested objects structure.

In your case it should be at least 4.

$newrole2=$newrole | ConvertTo-Json -Depth 4

Reference:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertto-json?view=powershell-7

Hope that helps.