Skip to content

Instantly share code, notes, and snippets.

@stijnmoreels
Last active November 15, 2019 07:03
Show Gist options
  • Save stijnmoreels/0bf6c64660c1da10dcea94ce3684bfc6 to your computer and use it in GitHub Desktop.
Save stijnmoreels/0bf6c64660c1da10dcea94ce3684bfc6 to your computer and use it in GitHub Desktop.
private static Outcome<JObject, string[]> Load(Stream content)
{
if (content is null)
{
throw new ArgumentNullException(nameof(content));
}
var settings = new JsonLoadSettings
{
CommentHandling = CommentHandling.Ignore,
DuplicatePropertyNameHandling = DuplicatePropertyNameHandling.Error,
LineInfoHandling = LineInfoHandling.Ignore
};
using var strReader = new StreamReader(content);
using var txtReader = new JsonTextReader(strReader);
try
{
return JObject.Load(txtReader, settings);
}
catch (JsonReaderException ex)
{
Logger.Error(ex, "Invalid JSON content stream caused an exception");
return new [] { "Content cannot be parsed to valid JSON" };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment