Reputation: 65
So I'm making a MySQL query, and one of the columns is a chunk of json that I want to set a particular subset of info to a variable. Wondering if I can condense my code a little. Right now my code is:
$data = Query -Query "select * from TABLE where fqdn = 'testhost.mycompany.com'"
$json = $data.request | ConvertFrom-Json
$WhatIreallyWant = $json.build_request
Can I condense the last two lines? build_request
is part of the request json.
Upvotes: 1
Views: 453
Reputation: 35408
You could use a pipeline like this
$WhatIWant = $data.request | ConvertFrom-Json | Select-Object -ExpandProperty build_request
or like suggested by TessellatingHeckler in the comments
$WhatIWant = ($data.request | ConvertFrom-Json).build_request
Upvotes: 2