I am trying to grab data from a Json file, and then output only the values associated to objects that have a field that reads "pass". I am not exactly sure how to proceed, as I've not touched powershell in a while now, and mostly been working on linux. I know it's probably just a simple command, but here is what I have so far:
$json = Get-Content 'file.json' | Out-String | ConvertFrom-Json
$output = $json.tests.results
I end up getting a whole bunch of stuff with results "bad", "warning", "pass", "fail". I only want to show the ones tagged as "pass"
JSON manipulation using Powershell
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.
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.
Re: JSON manipulation using Powershell
Again, not enough information to advise you on how to obtain the results desired. This is mostly because you have no PowerShell experience at teh level needed to understand the results or how to inspect objects and use the default CmdLets to filter objects/object collections.
Start with: "'help Select-Object', and 'help Where-Object'"
Start with: "'help Select-Object', and 'help Where-Object'"
Re: JSON manipulation using Powershell
I appreciate the reply, but maybe try to stop saying "you don't have enough experience" as though you're the only person who understands how to be a programmer.
I know the question sounds vague, but really I was trying to avoid pasting a bunch of json data that has sensitive info. Mainly I get results that I understand, but each column in the result has all the values I need and don't need.
For instance:
I just want the "pass results" to be showing, and the rest to be filtered out:
I know the question sounds vague, but really I was trying to avoid pasting a bunch of json data that has sensitive info. Mainly I get results that I understand, but each column in the result has all the values I need and don't need.
For instance:
- $output | Get-Members
- ID Result
- Whatever Bad
- Something-Else Warning
- Another-thing Pass
- Blah Fail
- And-Another Pass
I just want the "pass results" to be showing, and the rest to be filtered out:
- ID Result
- Another-Thing Pass
- And-Another Pass
Re: JSON manipulation using Powershell
Sorry but I have at least 40 years more experience and your question show you have little if any real programming experience. Simple coding is not programming beyond writing simple code. My statement was to help you think that maybe a book or other formal; method would help you to ask better technical questions. With very little effort you could ask better questions.
I will try to decode what you have posted. In technical forums we usually try not to male others have to decode our questions. I will try. Maybe I will guess right but maybe I can't.
Re: JSON manipulation using Powershell
The best guess is that you should filter on: "$_.Results -eq 'Pass'". Again a basic book on PowerShell would have shown you thins within two chapters.
Programmers are required to study any language they use to a fairly deep level. Writing a few lines of code is not programming. Programming is a tough technical discipline. PowerShell is designed for non-coders if you just want to write batch files.
Also use the PS help system to learn about the basic commands and how to use them.
I am not picking on you. This is advice given to all who enter technology at any level. If you want I can suggest books and other methods that can help you learn PowerShell and formal programming.
Programmers are required to study any language they use to a fairly deep level. Writing a few lines of code is not programming. Programming is a tough technical discipline. PowerShell is designed for non-coders if you just want to write batch files.
Also use the PS help system to learn about the basic commands and how to use them.
I am not picking on you. This is advice given to all who enter technology at any level. If you want I can suggest books and other methods that can help you learn PowerShell and formal programming.
Re: JSON manipulation using Powershell
You're pretty stupid for someone with 40 years of experience. Maybe you've just been repeating the same year forty times. It's a common problem with people who suffer from myopia. You could have also just started with "If you want I can suggest books and other methods that can help you learn PowerShell".
Most of my work has been in Java, and C/C++ on Linux, working on encryption. No programming to do with windows, until recently. Don't worry about the help, I've figured it out myself. Dipstick.
Most of my work has been in Java, and C/C++ on Linux, working on encryption. No programming to do with windows, until recently. Don't worry about the help, I've figured it out myself. Dipstick.
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: JSON manipulation using Powershell
Guys. Please keep it professional and courteous.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.