Evaluating json array objects. Please assist

I need to evaluate if current month and day is true based on start and end in each array object and if it is then print the cns value. Thank you for your help!

#json file

[pre]

{
"times": [{ "start": "01/01", "end": "03/01", "cns": "8" }, { "start": "04/01", "end": "07/01", "cns": "6" } ]
}
[/pre]

 

Hi, I don’t know how you are going to read this. Assuming, you are reading it from a file.

[pre]
$x = Get-Content C:\Temp\json.txt | ConvertFrom-Json
PS M:> $x.times

start end cns


01/01 03/01 8
04/01 07/01 6

[/pre]

After the ‘ConvertFrom-Json’ command, you will get a PSCustomObject and you can iterate through each item.

Thank you for your reply! How to iterate through each item?

Thanks!

 

Please start with learning the very basics of Powershell. It’s beyond the scope of any forum to teach you the fundamentals of any technology. You will have to learn that first.

You can use Foreach-Object or about_foreach.

Understand. Thank you for your time!