mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix ConvertFrom-Json to handle mutlilines
Fix #956 Add Newtonsoft.Json.JsonSerializationException to catch block that determines which mode to use: single-string or multi-string
This commit is contained in:
+6
@@ -93,6 +93,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
// The first input string does not represent a complete Json Syntax.
|
||||
// Hence consider the the entire input as a single Json content.
|
||||
}
|
||||
#if CORECLR
|
||||
catch (Newtonsoft.Json.JsonSerializationException)
|
||||
{
|
||||
// we use another serializer for CORECLR implementation
|
||||
}
|
||||
#endif
|
||||
if (successfullyConverted)
|
||||
{
|
||||
for (int index = 1; index < inputObjectBuffer.Count; index++)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
Describe 'ConvertFrom-Json' {
|
||||
It 'can convert a single-line object' {
|
||||
('{"a" : "1"}' | ConvertFrom-Json).a | Should Be 1
|
||||
}
|
||||
|
||||
It 'can convert one string-per-object' {
|
||||
$json = @('{"a" : "1"}', '{"a" : "x"}') | ConvertFrom-Json
|
||||
$json.Count | Should Be 2
|
||||
$json[1].a | Should Be 'x'
|
||||
}
|
||||
|
||||
It 'can convert mutli-line object' {
|
||||
$json = @('{"a" :', '"x"}') | ConvertFrom-Json
|
||||
$json.a | Should Be 'x'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user