I have the task of de-serializing a PSON (PowerShell Object Notation) file and am struggling to get it working. Apparently the PSON file is a variant of JSON used by Puppet which encodes the strings differently - according to this source
I have tried just using the standard JSON.Net DeserializeObject method:
using (var r = new StreamReader(psonFilePath))
{
string json = r.ReadToEnd();
dynamic jsonObject = JsonConvert.DeserializeObject(json);
}
The above code throws an exception:
"Unexpected character encountered while parsing value: @. Path '', line 0, position 0."
which makes sense as a standard JSON file wouldn't have an '@' at the start.
An example of the PSON file is below:
@{
shapes = @{
'SQ4297' = @{
shapeid = 'SQ4297'
shapetype = 'square'
sides = 'four'
colour = 'purple'
}
'SQ6281' = @{
shapeid = 'SQ6281'
shapetype = 'square'
sides = 'four'
colour = 'orange'
}
'TR14' = @{
shapeid = 'TR14'
shapetype = 'triange'
sides = 'three'
colour = 'green'
}
}
}
The link mentioned above states that
most parsers will produce usable output from PSON if they are instructed to interpret the input as Latin-1 encoding
I have tried using different encodings with the JSON but get similar errors whichever way I try. I also tried removing the '@' but then run into problems because the strings are not enclosed in quotes so the parser exceptions again.