1
    {
"count":  3,
"value":  [
              {
                  "id":  "12345678-123456-23424-123456ff2",
                  "name":  "TestProject",
                  "description":  "Test project  migration",
                  "url":  "https://dev.azure.com",
                  "state":  "wellFormed",
                  "revision":  6619,
                  "visibility":  "private",
                  "lastUpdateTime":  "2019-10-14T06:10:03.557Z"
              },
              {
                  "id":  "12345678-123456-23424-123456ff2",
                  "name":  "KC-TestAutomation-Framework",
                  "description":  "Test Automation Frameworks",
                  "url":  "https://dev.azure.com",
                  "state":  "wellFormed",
                  "revision":  6502,
                  "visibility":  "private",
                  "lastUpdateTime":  "2019-10-03T07:53:33.95Z"
              },
              {
                  "id":  "b2345678-123456-23424-12345",
                  "name":  "Training",
                  "description":  "Training Management Project",
                  "url":  "https://dev.azure.com",
                  "state":  "wellFormed",
                  "revision":  7124,
                  "visibility":  "private",
                  "lastUpdateTime":  "2019-12-02T07:19:24Z"
              }
     ]
}

I've this Json, I need to create from this json another json containing the name,and ID of every project in this form name:name value:id in json file...

I've tried somenthing like this..

   $json = Get-Content $file | ConvertFrom-Json 

   ForEach($i in $json.value.id)
    {
      Write-Host "Id: $($i)","name: $($json.value.name)"
    }
3
  • foreach($project in $projects.value) { Write-Output "name:$($project.name)" "value:$($project.id)" *>> $path/.json } Commented Feb 8, 2020 at 10:57
  • This should not be difficult.. What have you tried yourself and why did that not work? Commented Feb 8, 2020 at 10:58
  • I Kwow it's easy, but I'm lost... I've tried somenthing like this $json = Get-Content $file | ConvertFrom-Json ForEach($i in $json.value.id) { Write-Host "Id: $($i)","name: $($json.value.name)" } Commented Feb 8, 2020 at 11:20

1 Answer 1

2
  • Read the JSON file and convert it using ConvertFrom-Json.
  • Select the id and name properties and convert back to json
  • Write the newly created json to file

Something like this:

$json = Get-Content -Path 'X:\YourJsonFile.json' | ConvertFrom-Json

$newJson = $json.value | Select-Object id, name | ConvertTo-Json

# output on screen
$newJson

# output to new json file
$newJson | Set-Content -Path 'X:\YourNewJsonFile.json'

Output:

[
    {
        "id":  "12345678-123456-23424-123456ff2",
        "name":  "TestProject"
    },
    {
        "id":  "12345678-123456-23424-123456ff2",
        "name":  "KC-TestAutomation-Framework"
    },
    {
        "id":  "b2345678-123456-23424-12345",
        "name":  "Training"
    }
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.