Parse JSON into list

Last modified 1 year ago
Danger icon
The last modifications of this post were around 1 year ago, some information may be outdated!


Quickly parse that JSON list into a stongly typed list object for use.


Duck object used here is assumed to be defined elsewhere in code. Code assumed JSON is structured properly for object.


using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;

var pathToSeedData = Path.Combine(Directory.GetCurrentDirectory(), "Data", "duck_seed.json");
var dataSet = File.ReadAllText(pathToSeedData);
var seedData = JsonConvert.DeserializeObject<List<Duck>>(dataSet);