You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the ConvertTo-Json cmdlet assembles all input objects into an in-memory List, then converts that to one Json string for output. This can be inefficient if there are many input objects.
Enhancing ConvertTo-Json to (optionally) convert each input object to a complete Json string and output
as it is processed offers these benefits:
reduced memory usage
substantially improved throughput when the output stream is being processed by a separate thread
or process.
Good idea, but I suggest calling the parameter -Stream instead, analogous to Out-String's conceptually related parameter.
It's also worth spelling out how this will affect the output for multiple input objects:
'a', 'b' | ConvertTo-Json -Compress yields a single output string (irrespective of the number of input objects) that is a JSON array, verbatim ["a","b"]
'a', 'b' | ConvertTo-Json -Stream -Compress will yield two output strings (that will be streamed as they become available), verbatim "a" and "b" (which when captured will become @('"a"', '"b"'))
Thanks, Paul Hilchey (@paulhilchey), but note that -Compress is incidental to the issue at hand; I merely used it to show the current output for multi-object input more concisely.
There's a few questions/issues I have with the ConvertFrom-Json request
Is there a good reason to block just doing ConvertTo-Json for this
Why not have it as a separate issue and add it based on demand like other features
A bigger question is what does -Stream add to ConvertFrom-Json that it doesn't already have? For example it already streams in a way by emitting each individual objects from the input
The only thing I can think of is to emit the objects as they are processed but I cannot see why that just can't be the default behaviour and why a switch would be needed for that?
Activity
paulhilchey commentedon Nov 26, 2025
Pull request with the code changes: #25597
Related documentation issue: MicrosoftDocs/PowerShell-Docs#12104
mklement0 commentedon Nov 27, 2025
Good idea, but I suggest calling the parameter
-Streaminstead, analogous toOut-String's conceptually related parameter.It's also worth spelling out how this will affect the output for multiple input objects:
'a', 'b' | ConvertTo-Json -Compressyields a single output string (irrespective of the number of input objects) that is a JSON array, verbatim["a","b"]'a', 'b' | ConvertTo-Json -Stream -Compresswill yield two output strings (that will be streamed as they become available), verbatim"a"and"b"(which when captured will become@('"a"', '"b"'))paulhilchey commentedon Dec 2, 2025
I'm happy to call the parameter
-Streamif that is the consensus.I'll see about documenting the behaviour with
-Compresstoo.iSazonov commentedon Dec 2, 2025
We need WG approve before PR.
mklement0 commentedon Dec 2, 2025
Thanks, Paul Hilchey (@paulhilchey), but note that
-Compressis incidental to the issue at hand; I merely used it to show the current output for multi-object input more concisely.iSazonov commentedon Dec 4, 2025
#25597 (comment)
This was approved by maintainers with the wish to have this parameter for ConvertFrom-Json too.
Paul Hilchey (@paulhilchey) Please update the issue title and description.
jborean93 commentedon Dec 9, 2025
There's a few questions/issues I have with the
ConvertFrom-JsonrequestConvertTo-Jsonfor thisA bigger question is what does
-Streamadd toConvertFrom-Jsonthat it doesn't already have? For example it already streams in a way by emitting each individual objects from the inputThe only thing I can think of is to emit the objects as they are processed but I cannot see why that just can't be the default behaviour and why a switch would be needed for that?