-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Change min depth to 0 for ConvertTo-Json #13700
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
Conversation
|
I don't see any value in the change. If we plan to move new .Net Json API and follow the API behavior the change makes no sense at all. |
|
@iSazonov From what I understand you want to take away the ability to choose depth right? Why do you want to limit how people use PowerShell? Some choices may make no sense to you, but for other people, it makes a lot of sense. NET is NET, PowerShell is PowerShell - they serve a different purpose. |
|
What does depth 0 mean? |
|
@TravisEz13 #13660 describes why I want Depth 0. |
|
The short of it is that depth 0 is "flat" with no nesting at all. |
$Object = [PSCustomObject] @{
AnotherObject = @{
Test = 0
}
AnotherObject1 = @{
LetsSett = 'dfdf'
OhNo = @{
OrAnotherLevel = @{
AndAnother = @{
Color = [System.Drawing.Color]::AliceBlue
}
}
}
}
}
$Object | ConvertTo-Json -Depth 1Output: What I'm after: Of course for nested hashtables the visual part will be bad. But what I'm after actually is same behavior: $Object | ConvertTo-Html -FragmentOutput: |
|
Can you rebase to try to fix the errors? |
|
@TravisEz13 fixed |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@TravisEz13 are we doing this ? |
test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Json.Tests.ps1
Outdated
Show resolved
Hide resolved
|
I wrote a bunch of tests for my own ConvertTo-jsonLiteral which has a difference by default having Depth 0 and has additional settings such as BoolAsString, NumberAsString, DateTimeFormat where you can push how the date is formatted as a string, and NewLineFormatting. I do all that because I want it sometimes to behave like ConvertTo-HTML + usually JSON based queries for REST API don't like types or other stuff from native cmdlets. Maybe it will help, as most of the tests should work on the original cmdlets as I try to validate it with PowerShell implementation with a difference of testing additional parameters in most cases. But I do tests arrays, strings, enums and so on. https://github.com/EvotecIT/PSSharedGoods/blob/master/Tests/ConvertTo-JsonLiteral.Tests.ps1 Feel free to copy/adjust and enhance if you see any benefit.
|
test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Json.Tests.ps1
Show resolved
Hide resolved
…-Json.Tests.ps1 update as per suggestion Co-authored-by: Ilya <darpa@yandex.ru>
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
Just a gentle reminder @TravisEz13 :-) |
Update ChangeLog for v7.2.0-preview.3 release
|
Somebody please help to fix the CI error. |
|
@kvprasoon It seems unrelated to the PR, please rebase. |
Update ChangeLog for v7.1.2 release Co-authored-by: Dongbo Wang <dongbow@microsoft.com>
…-Json.Tests.ps1 update as per suggestion Co-authored-by: Ilya <darpa@yandex.ru>
…into json-depth
|
@kvprasoon I see unrelated commits. Please fix your rebase. |
|
@iSazonov ohh yeah...donno how did this happen, was doing the changes from different laptops. Will fix it. |
|
@iSazonov @TravisEz13 Closing and I've created a fresh one here #14830 |
PR Summary
Change min depth to 0 for ConvertTo-Json
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.