Skip to content

Change min depth to 0 for ConvertTo-Json - #13700

Closed
PRASOON KARUNAN V (kvprasoon) wants to merge 21 commits into
PowerShell:masterfrom
kvprasoon:json-depth
Closed

PRASOON KARUNAN V (kvprasoon) wants to merge 21 commits into
PowerShell:masterfrom
kvprasoon:json-depth

Conversation

@kvprasoon

Copy link
Copy Markdown
Contributor

PR Summary

Change min depth to 0 for ConvertTo-Json

PR Checklist

@iSazonov

Copy link
Copy Markdown
Collaborator

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.

@PrzemyslawKlys

Przemysław Kłys (PrzemyslawKlys) commented Sep 27, 2020 •

Copy link
Copy Markdown

Ilya (@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.

@TravisEz13

Copy link
Copy Markdown
Member

What does depth 0 mean?

@PrzemyslawKlys

Copy link
Copy Markdown

Travis Plunk (@TravisEz13) #13660 describes why I want Depth 0.

@vexx32

Rain Sallow (/u/ta11ow) (vexx32) commented Oct 2, 2020 •

Copy link
Copy Markdown
Collaborator

The short of it is that depth 0 is "flat" with no nesting at all.

@PrzemyslawKlys

Copy link
Copy Markdown
$Object = [PSCustomObject] @{
    AnotherObject  = @{
        Test = 0
    }
    AnotherObject1 = @{
        LetsSett = 'dfdf'
        OhNo     = @{
            OrAnotherLevel = @{
                AndAnother = @{
                    Color = [System.Drawing.Color]::AliceBlue
                }
            }
        }
    }
}
$Object | ConvertTo-Json -Depth 1

Output:

{
    "AnotherObject":  {
                          "Test":  0
                      },
    "AnotherObject1":  {
                           "OhNo":  "System.Collections.Hashtable",
                           "LetsSett":  "dfdf"
                       }
}

What I'm after:

{
"AnotherObject":"System.Collections.Hashtable",
"AnotherObject1":"System.Collections.Hashtable"
}

Of course for nested hashtables the visual part will be bad. But what I'm after actually is same behavior:

$Object | ConvertTo-Html -Fragment

Output:

<table>
<colgroup><col/><col/></colgroup>
<tr><th>AnotherObject</th><th>AnotherObject1</th></tr>
<tr><td>System.Collections.Hashtable</td><td>System.Collections.Hashtable</td></tr>
</table>

@TravisEz13

Copy link
Copy Markdown
Member

Can you rebase to try to fix the errors?

@kvprasoon

Copy link
Copy Markdown
Contributor Author

Travis Plunk (@TravisEz13) fixed

@ghost ghost added the Review - Needed The PR is being reviewed label Oct 13, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@kvprasoon

Copy link
Copy Markdown
Contributor Author

Travis Plunk (@TravisEz13) are we doing this ?

Comment thread test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Json.Tests.ps1 Outdated
@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed labels Dec 15, 2020
@PrzemyslawKlys

Przemysław Kłys (PrzemyslawKlys) commented Dec 15, 2020 •

Copy link
Copy Markdown

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.

GitHub
PSSharedGoods is little PowerShell Module that primary purpose is to be useful for multiple tasks, unrelated to each other. I've created this module as “a glue” between my other modules. - Evo...

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Dec 16, 2020
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Dec 16, 2020
@ghost ghost added the Review - Needed The PR is being reviewed label Dec 26, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@kvprasoon

Copy link
Copy Markdown
Contributor Author

Just a gentle reminder Travis Plunk (@TravisEz13) :-)

@kvprasoon

PRASOON KARUNAN V (kvprasoon) commented Feb 13, 2021 •

Copy link
Copy Markdown
Contributor Author

Somebody please help to fix the CI error.

@iSazonov

Copy link
Copy Markdown
Collaborator

PRASOON KARUNAN V (@kvprasoon) It seems unrelated to the PR, please rebase.

@ghost ghost removed the Review - Needed The PR is being reviewed label Feb 13, 2021
@iSazonov

Copy link
Copy Markdown
Collaborator

PRASOON KARUNAN V (@kvprasoon) I see unrelated commits. Please fix your rebase.

@kvprasoon

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) ohh yeah...donno how did this happen, was doing the changes from different laptops. Will fix it.

@kvprasoon

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) Travis Plunk (@TravisEz13) Closing and I've created a fresh one here #14830

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants