1

I'm trying to read a Json file with some passwords but them are stored into Key-Value pattern as below:

{
    "id":  "a8cc4184-3844-4605-8e35-ea479ae1094e",
    "name":  "Test Credentials and Secrets",
    "values":  [
                   {
                       "key":  "apassword",
                       "value":  "mypassword",
                       "enabled":  true
                   },
                   {
                       "key":  "tpassword",
                       "value":  "my other password",
                       "enabled":  true
                   },
               ],
    "exported_using":  "Postman/7.34.0"
}

How can I get any specific value with PowerShell? tpassword value for instance.

1 Answer 1

4

I would recommend using ConvertFrom-Json to turn it into an Object so you can then access the properties easily with PowerShell.

I saved the json above to C:\temp\json.json and then the following got me the tpassword value:

$json = Get-Content C:\temp\json.json | ConvertFrom-Json
$json.values | Where-Object key -eq 'tpassword' | Select-Object Value

PowerShell terminal showing results

Sign up to request clarification or add additional context in comments.

4 Comments

Hey, your console looks cool! Is this a special app or an extension of the regular pwsh console?
It's Windows terminal with an oh my posh prompt (ohmyposh.dev).
I've copied this code, and Write-Host $json shows the JSON data block, but Write-Host $json.values outputs a blank line -- why?
I have posted a new question here

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.