using Newtonsoft.Json;
using Newtonsoft.Json.Bson;
namespace adas_core.Domain.Utils;
///
/// Provides extension methods for JSON-related operations.
///
public static class JsonExtensions
{
///
/// Reads JSON content from the specified input file and writes it as BSON to the output file.
/// By default, uses , which requires the output file to not already exist.
///
/// The path to the source JSON file to read from.
/// The path to the destination BSON file to write to.
/// The file mode used to open the output file. Defaults to .
public static void CopyToBson(string inputPath, string outputPath, FileMode fileMode = FileMode.CreateNew)
{
using var textReader = File.OpenText(inputPath);
using var jsonReader = new JsonTextReader(textReader);
using var oFileStream = new FileStream(outputPath, fileMode);
using var dataWriter = new BsonDataWriter(oFileStream);
dataWriter.WriteToken(jsonReader);
}
}