0

Dear Stackoverflow Community

I wanted to know if there is a way to do the exact same thing as here:
checking if json value is empty
but in Powershell.

For Example my JSON File looks like this:

{
    "Username":  "",
    "Password":  ""
}

Now I want to check if the value of Username (for example) is empty or not.

I am working with the newest version of Powershell.
I have searched for a pretty long time and did not find anything, so I really hope you can help me.

Greetings

Martin

2

1 Answer 1

1

Its very easy in PowerShell, load the file, convert from Json check the value:

$myobject = Get-Content C:\temp\CheckEmpty.json | ConvertFrom-Json

if ($myobject.Username -eq "") {
    Write-Output "Username is empty"
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the great answer! But how would it look when I would want to check both Username and Password? Greetings
@MartinSchmidt You need to put some more effort into this and at least try to understand. ;) If you read the code you should be able to understand how to do it.
Actually, I did find a solution. Kind of. I am now just checking if Username OR Password is empty. Still have not found a solution for AND OR yet

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.