Skip to content

Conversation

@kvprasoon
Copy link
Contributor

PR Summary

Change min depth to 0 for ConvertTo-Json

PR Checklist

@ghost ghost assigned TravisEz13 Sep 25, 2020
@iSazonov
Copy link
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
Copy link

PrzemyslawKlys commented Sep 27, 2020

@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
Member

What does depth 0 mean?

@PrzemyslawKlys
Copy link

@TravisEz13 #13660 describes why I want Depth 0.

@vexx32
Copy link
Collaborator

vexx32 commented Oct 2, 2020

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

@PrzemyslawKlys
Copy link

$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
Member

Can you rebase to try to fix the errors?

@kvprasoon
Copy link
Contributor Author

@TravisEz13 fixed

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

ghost commented Oct 13, 2020

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
Contributor Author

@TravisEz13 are we doing this ?

@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
Copy link

PrzemyslawKlys commented Dec 15, 2020

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 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

ghost commented Dec 26, 2020

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
Contributor Author

Just a gentle reminder @TravisEz13 :-)

@kvprasoon
Copy link
Contributor Author

kvprasoon commented Feb 13, 2021

Somebody please help to fix the CI error.

@iSazonov
Copy link
Collaborator

@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
Collaborator

@kvprasoon I see unrelated commits. Please fix your rebase.

@kvprasoon
Copy link
Contributor Author

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

@kvprasoon
Copy link
Contributor Author

@iSazonov @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