Last active
September 16, 2017 22:47
-
-
Save matt40k/fab6ca579c355a0862a0a2ffb8166330 to your computer and use it in GitHub Desktop.
For some reason ConvertTo-Json messes up within a function - what am I missing? Note-Now fixed, this isn't c#, see commits to see fix. (https://gist.github.com/matt40k/fab6ca579c355a0862a0a2ffb8166330/revisions)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$v1 | |
$v2 | |
Function GetJson($value1, $value2) | |
{ | |
$j = @{"test"=$value1;"test2"=$value2} | ConvertTo-Json | |
return $j | |
} | |
$v1 = "test123" | |
$v2 = "test321" | |
$result = GetJson $v1 $v2 | |
Write-Host $result | |
#Returns (incorrect) | |
#{ | |
# "test": [ | |
# "test123", | |
# "test321" | |
# ], | |
# "test2": null | |
#} | |
$value1=$v1 | |
$value2=$v2 | |
$j2 = @{"test"=$value1;"test2"=$value2} | ConvertTo-Json | |
Write-Host $j2 | |
#Returns (correct) | |
#{ | |
# "test": "test123", | |
# "test2": "test321" | |
#} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment