-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add -AsHashtable switch to ConvertFrom-Json for issue #3623 #5043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TravisEz13
merged 13 commits into
PowerShell:master
from
bergmeister:ConvertFromJsonAsHashTable
Oct 25, 2017
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d06de27
Add -AsHashtable switch to ConvertFrom-Json for issue 3623
bergmeister b8dd5b6
Keep old ConvertFromJson API for backwards compatibility and address …
bergmeister a709c29
Remove redundant '[Parameter(Mandatory = false)]' on -AsHashtable swi…
bergmeister e1fe619
Last commit accidentally removed entirely [Parameter()] line, it shou…
bergmeister c334128
-Revert change in InvokeRestMethodCommand originally made in this PR …
bergmeister 0d5a6fb
Detect if key is empty string to resolve 1755 issue by redirecting to…
bergmeister af44072
Fix test syntax and simplify test name
bergmeister 123128c
make 'json' uppercase 'JSON' in error message as suggested in PR review.
bergmeister 69df716
Address PR comments about tests (mostly style) by @iSazonov
bergmeister 7d77ae2
Update JsonObject.Tests.ps1
bergmeister db0d6ce
Report error when keys have different casing. As part of this I also …
bergmeister dfa9126
Add more validation to positive tests and shorten error message as re…
bergmeister 935054b
Minor syntax simplification in jsonobject.tests.ps1
bergmeister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
32 changes: 26 additions & 6 deletions
32
test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Json.Tests.ps1
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,36 @@ | ||
| Describe 'ConvertFrom-Json' -tags "CI" { | ||
| It 'can convert a single-line object' { | ||
| ('{"a" : "1"}' | ConvertFrom-Json).a | Should Be 1 | ||
|
|
||
| BeforeAll { | ||
| $testCasesWithAndWithoutAsHashtableSwitch = @( | ||
| @{ AsHashtable = $true } | ||
| @{ AsHashtable = $false } | ||
| ) | ||
| } | ||
|
|
||
| It 'can convert one string-per-object' { | ||
| $json = @('{"a" : "1"}', '{"a" : "x"}') | ConvertFrom-Json | ||
|
|
||
| It 'Can convert a single-line object with AsHashtable switch set to <AsHashtable>' -TestCase $testCasesWithAndWithoutAsHashtableSwitch { | ||
| Param($AsHashtable) | ||
| ('{"a" : "1"}' | ConvertFrom-Json -AsHashtable:$AsHashtable).a | Should Be 1 | ||
| } | ||
|
|
||
| It 'Can convert one string-per-object with AsHashtable switch set to <AsHashtable>' -TestCase $testCasesWithAndWithoutAsHashtableSwitch { | ||
| Param($AsHashtable) | ||
| $json = @('{"a" : "1"}', '{"a" : "x"}') | ConvertFrom-Json -AsHashtable:$AsHashtable | ||
| $json.Count | Should Be 2 | ||
| $json[1].a | Should Be 'x' | ||
| if ($AsHashtable) | ||
| { | ||
| $json | Should BeOfType Hashtable | ||
| } | ||
| } | ||
|
|
||
| It 'can convert multi-line object' { | ||
| $json = @('{"a" :', '"x"}') | ConvertFrom-Json | ||
| It 'Can convert multi-line object with AsHashtable switch set to <AsHashtable>' -TestCase $testCasesWithAndWithoutAsHashtableSwitch { | ||
| Param($AsHashtable) | ||
| $json = @('{"a" :', '"x"}') | ConvertFrom-Json -AsHashtable:$AsHashtable | ||
| $json.a | Should Be 'x' | ||
| if ($AsHashtable) | ||
| { | ||
| $json | Should BeOfType Hashtable | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add 'else' with Diagnostics.Assert (if the object is not JObject or JArray).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the cast to
JArraya few lines above,objcannot be something else. I initially put your suggestion in but even the compiler tells me that:error CS0184: The given expression is never of the provided ('JObject') typeUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant: