2021-09-05 20:54:44 +01:00
|
|
|
|
using Common;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.Encodings.Web;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text.Unicode;
|
|
|
|
|
|
|
|
|
|
namespace AssortGenerator.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);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"Writing json file to {outputPath}");
|
|
|
|
|
|
|
|
|
|
var options = new JsonSerializerOptions
|
|
|
|
|
{
|
|
|
|
|
WriteIndented = true,
|
2022-07-24 22:22:53 +01:00
|
|
|
|
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
|
2021-09-05 20:54:44 +01:00
|
|
|
|
Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Cyrillic)
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
var json = JsonSerializer.Serialize(itemToSerialise, options);
|
|
|
|
|
File.WriteAllText($"{outputPath}\\{fileName}.json", json);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|