I'm trying to port the last piece of code I have that is dependent on Newtonsoft.Json
to System.Text.Json
.
The code parses a JSON fragment and flattens it. This is generated by a legacy system so we'd rather not change that if possible.
// Comment here including the person who last made a change to the program
[
// Comment here with the date this value set was changed
[ "value1", "value2", "value3" ],
// Comment here with the date this value set was changed
[ "value1", "value2", "value3" ],
// Repeat over and over for all data
]
I have been parsing this for Newtonsoft.Json
using the following code:
using (var sr = new StreamReader(stream))
{
var array = JArray.Parse(sr.ReadToEnd());
var flattened = array.SelectMany(x => x).ToArray();
foreach (var item in flattened)
items.Add(item.ToObject<string>());
}
The code above pulls each of the values that are within the JSON payload and puts them into a list called items
.
How can I parse JSON in the format above using System.Text.Json
?