-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
43 lines (38 loc) · 1.33 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.IO;
using System.Text.Json;
using System.Xml;
using Newtonsoft.Json;
using YamlDotNet.Serialization;
class Program
{
static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Usage: dotnet run <yamlFilePath> <jsonFilePath>");
return;
}
string yamlFilePath = args[0];
string jsonFilePath = args[1];
try
{
using (var yamlInput = new FileStream(yamlFilePath, FileMode.Open, FileAccess.Read))
using (var jsonOutput = new FileStream(jsonFilePath, FileMode.Create, FileAccess.Write))
{
var yamlObject = new Deserializer().Deserialize(new StreamReader(yamlInput));
var jsonSerializer = new Newtonsoft.Json.JsonSerializer();
jsonSerializer.Formatting = Newtonsoft.Json.Formatting.Indented;
using (var jsonOutputStream = new StreamWriter(jsonOutput))
{
jsonSerializer.Serialize(jsonOutputStream, yamlObject);
}
}
Console.WriteLine($"Successfully converted {yamlFilePath} to {jsonFilePath}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}