I have an array of hashtables $a (I give a very simplyfied example):
$a = @()
$a += @{id=1; name='Aron' }
$a += @{id=2; name='Benny'}
$a
Result:
Name Value
---- -----
id 1
name Aron
id 2
name Benny
I try to serialize and then deserialize it, using the json fonctionality in Powershell 5.1:
$b = $a | ConvertTo-Json | ConvertFrom-Json
but the two objects are not the same, which is the goal.
$b
Result:
id name
-- ----
1 Aron
2 Benny
The types are the same:
$a.getType()
$b.getType()
Result:
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
I’ve tried all kind of combinations of getEnumerator() and out-string, with no succes.
What to do to use jSON conversion back and forth, and get the same array of hashtables in the end?
The reason I need this: the JSON conversion should save the serialized array in a file and be able to fetch it and deserialize it later.