Insert value in JSON

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
danpotter
Posts: 5
Joined: Sun Mar 03, 2013 11:45 am

Insert value in JSON

Post by danpotter »

Hi JRV.. long time!! I've been out of the PS arena for quite awhile and I have this json driving me mad. I need to insert 'test' into the in: array. Trying to insert new object in NOT tells me that NOT can't be found. Trying to += IN, tells me the property IN can't be found.
  1. {
  2.  
  3.     "if":  {
  4.  
  5.                "allOf":  [
  6.  
  7.                              {
  8.  
  9.                                  "not":  {
  10.  
  11.                                              "field":  "tags.Financial",
  12.  
  13.                                              "in":  [
  14.  
  15.                                                         "prod",
  16.  
  17.                                                         "dev"
  18.  
  19.                                                        
  20.  
  21.                                                     ]
  22.  
  23.                                          }
  24.  
  25.                              },
  26.  
  27.                              {
  28.  
  29.                                  "field":  "type",
  30.  
  31.                                  "equals":  "Microsoft.Resources/subscriptions/resourceGroups"
  32.  
  33.                              }
  34.  
  35.                          ]
  36.  
  37.            },
  38.  
  39.     "then":  {
  40.  
  41.                  "effect":  "deny"
  42.  
  43.              }
  44.  
  45. }

User avatar
danpotter
Posts: 5
Joined: Sun Mar 03, 2013 11:45 am

Re: Insert value in JSON

Post by danpotter »

This seems to do it.

Add-Member -InputObject $a.if.allof.not -Type noteproperty -Value $arr -Name in -Force

Locked