1

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.

1
  • 2
    $WhatIreallyWant = ($data.request | ConvertFromJson).build_request ? Commented Aug 9, 2016 at 15:51

1 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

1 Comment

Indeed it did. Thanks!

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.