4 ms·
I'm sure someone's going to throw a shoe at me for this, but...this sort of thing is why you want an object-oriented shell. PS C:\> $x = ConvertFrom-Json -Inpu
by 13of40 10y ago
I'm sure someone's going to throw a shoe at me for this, but...this sort of thing is why you want an object-oriented shell.
PS C:\> $x = ConvertFrom-Json -InputObject '[{"banana" : {"stem" : "brown", "peel" : "yellow", "flesh" : "white"}}]'
PS C:\> $x.banana.peel
yellow
- awssailin 10y agoI don't want an object oriented shell but I have on occasion found jq to be very useful.
- fabianfabian 10y ago$ echo '[{"banana" : {"stem" : "brown", "peel" : "yellow", "flesh" : "white"}}]' | jq '.[].banana.peel' "yellow"
- 13of40 10y agoCome on now, you're missing the point. If the lingua franca of your shell is objects instead of text, you can import from whatever format you want and work with it in high fidelity: PS C:\> $x = [XML]"<banana><stem>brown</stem><peel>yellow</peel><flesh>white</flesh></banana>" PS C:\> $x.banana.peel yellow PS C:\> $x = ConvertFrom-Json -InputObject '[{"banana" : {"stem" : "brown", "peel" : "yellow", "flesh" : "white"}}]' PS C:\> $x.banana.peel yellow PS C:\> $x = New-Object PSObject -Property @{banana = New-Object PSObject -Property @{stem = "brown"; peel = "yellow"; flesh = "white"}} PS C:\> $x.banana.peel yellow PS C:\> $x = @{banana = @{stem = "brown"; peel = "yellow"; flesh = "white"}} PS C:\> $x.banana.peel yellow
- fabianfabian 10y agoGood point, thanks for clarifying.
- taeric 10y agoI won't throw shoes. However, I do prefer anything that forces a commands output into text. Which JSON at least gets that right. Specifically, if I have something that output objects, it is possible (and likely) that I can not persist that output to less and explore what is going on. Great if I already know exactly what I want. Terrible if I just want a visual exploration. Worse, if I can't dump it to file, I may have to constantly do some expensive operations just to find out what will give me the answer I want.
- rhubarbquid 10y agoIt might be interesting to try... but switching operating systems is kind of a big step just to try another shell. Or is there some OO shell that works on Mac or Linux that I don't know about?
- marmaduke 10y agoPython?