How To use Complex Json data in Power shell body

Welcome Forums General PowerShell Q&A How To use Complex Json data in Power shell body

Viewing 3 reply threads
  • Author
    Posts
    • #187720
      Participant
      Topics: 4
      Replies: 2
      Points: 43
      Rank: Member

      Hi, I have complex raw data in json, I want to using that in body of power shell script

      here is my json:

      {
      "request": "success",
      "consent": true,
      "source": [
      {
      "type": " ",
      "content": [
      {
      "type": " ",
      "meta": {
      "sample_type": " "
      },
      "deatail": " "
      }
      ]
      }
      ],
      "destination": [
      {
      "type": " ",
      "content": [
      {
      "type": "",
      "meta": {
      "sample_type": "",
      },
      "deatils" :" "
      }
      ]
      }
      ]
      }

       

       

       

    • #187756
      Participant
      Topics: 2
      Replies: 136
      Points: 714
      Helping Hand
      Rank: Major Contributor

      Hi Sonali29526,

      Can you please elaborate your query in detailed?

      Thank you.

    • #187834
      Participant
      Topics: 9
      Replies: 1277
      Points: 1,051
      Helping Hand
      Rank: Community Hero

      Assume you're referring to a REST API body...

      #Method 1 - HashTables {} and Arrays ()
      
      $json = @{ 
          Property1 = 'Foo';
          Property2='Faa'
          PropertyArray = @(@{
              Item1 = 'Blah'
              Item2 = 'BlahBlah'
          })
      }
      
      $json | ConvertTo-Json
      
      
      
      #Method 2 - Here String with Variables
      $variable1 = 'Foo'
      $variable2 = 'Faa'
      
      $json = @"
      {
          "Property1":  "$($Variable1)",
          "Property2":  "$($variable2)",
          "PropertyArray":  [
                                {
                                    "Item1":  "Blah",
                                    "Item2":  "BlahBlah"
                                }
                            ]
      }
      "@
      
      $json
      
    • #187867
      Participant
      Topics: 4
      Replies: 2
      Points: 43
      Rank: Member

      Thanks a lot.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.