31 lines
940 B
C#
31 lines
940 B
C#
|
using AssortHelpers.Helpers;
|
|||
|
using System;
|
|||
|
using System.IO;
|
|||
|
using System.Text.Encodings.Web;
|
|||
|
using System.Text.Json;
|
|||
|
|
|||
|
namespace AssortValidator.Common
|
|||
|
{
|
|||
|
public static class JsonWriter
|
|||
|
{
|
|||
|
public static void WriteJson<T>(T itemToSerialise, string outputFolderName, string workingPath, string fileName)
|
|||
|
{
|
|||
|
var outputPath = $"{workingPath}\\output\\{outputFolderName}";
|
|||
|
DiskHelpers.CreateDirIfDoesntExist(outputPath);
|
|||
|
|
|||
|
var options = new JsonSerializerOptions
|
|||
|
{
|
|||
|
WriteIndented = true,
|
|||
|
IgnoreNullValues = true,
|
|||
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
|||
|
|
|||
|
};
|
|||
|
var json = JsonSerializer.Serialize(itemToSerialise, options);
|
|||
|
File.WriteAllText($"{outputPath}\\{fileName}.json", json);
|
|||
|
|
|||
|
|
|||
|
Console.WriteLine($"wrote {fileName}.json file to {outputPath}");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|