using System.Collections.Generic;
public static void Main()
var inputFilePath = "input.json";
File.WriteAllText(inputFilePath, json);
foreach (var stepsFilePath in SplitBySteps(inputFilePath))
SplitByInstrumentData(stepsFilePath);
File.Delete(stepsFilePath);
static string[] SplitByInstrumentData(string stepsFilePath)
List<string> stepsFiles = new List<string>();
dynamic stepsKeys = null;
using (var r = new ChoJSONReader(stepsFilePath).WithJSONPath("$..Job.Keys"))
keys = r.FirstOrDefault();
using (var r = new ChoJSONReader(stepsFilePath).WithJSONPath("$..Job.Props"))
props = r.FirstOrDefault();
using (var r = new ChoJSONReader(stepsFilePath).WithJSONPath("$..Job.Steps.Keys"))
stepsKeys = r.FirstOrDefault();
using (var r = ChoJSONReader.LoadText(json).WithJSONPath("$..Job.Steps.InstrumentData")
.Setup(s => s.RowsLoaded += (o, e) => $"InstrumentData Nodes loaded: {e.RowsLoaded} <- {DateTime.Now}".Print())
.Configure(c => c.CustomJObjectLoader = (sr, s) =>
string outFilePath = $"InstrumentData_{fileCount++}.json";
$"Writing to `{outFilePath}` file...".Print();
using (var topJo = new ChoJObjectWriter(outFilePath))
topJo.Formatting = Newtonsoft.Json.Formatting.Indented;
using (var jo = new ChoJObjectWriter("Job", topJo))
jo.WriteProperty("Keys", keys);
jo.WriteProperty("Props", props);
jo.WriteProperty("Steps", sr);
File.ReadAllText(outFilePath).Print();
stepsFiles.Add(outFilePath);
return ChoJSONObjects.EmptyJObject;
return stepsFiles.ToArray();
static string[] SplitBySteps(string inputFilePath)
List<string> stepsFiles = new List<string>();
using (var r = new ChoJSONReader(inputFilePath).WithJSONPath("$..Job.Keys"))
keys = r.FirstOrDefault();
using (var r = new ChoJSONReader(inputFilePath).WithJSONPath("$..Job.Props"))
props = r.FirstOrDefault();
using (var r = ChoJSONReader.LoadText(json).WithJSONPath("$..Job.Steps")
.Setup(s => s.RowsLoaded += (o, e) => $"Step Nodes loaded: {e.RowsLoaded} <- {DateTime.Now}".Print())
.Configure(c => c.CustomJObjectLoader = (sr, s) =>
string outFilePath = $"Steps_{fileCount++}.json";
$"Writing to `{outFilePath}` file...".Print();
using (var topJo = new ChoJObjectWriter(outFilePath))
topJo.Formatting = Newtonsoft.Json.Formatting.Indented;
using (var jo = new ChoJObjectWriter("Job", topJo))
jo.WriteProperty("Keys", keys);
jo.WriteProperty("Props", props);
jo.WriteProperty("Steps", sr);
stepsFiles.Add(outFilePath);
return ChoJSONObjects.EmptyJObject;
return stepsFiles.ToArray();
static void PrintLibVersion()
$"{typeof(ChoJSONReader).Assembly.GetName().Name} v{typeof(ChoJSONReader).Assembly.GetName().Version.ToString()}".Print();
""FileType"": ""Measurements"",
""InstrumentDescriptions"": [
""InstrumentID"": ""1723007"",
""InstrumentType"": ""Actual1"",
""DataType"": ""Double"",
""InstrumentID"": ""2424009"",
""InstrumentType"": ""Actual2"",
""DataType"": ""Double"",
""StepResult"": ""NormalEnd""
""InstrumentID"": ""1723007""
""DateTime"": ""2021-11-16 21:18:37.000"",
""DateTime"": ""2021-11-16 21:18:37.100"",
""DateTime"": ""2021-11-16 21:18:37.200"",
""DateTime"": ""2021-11-16 21:18:37.300"",
""DateTime"": ""2021-11-16 21:18:37.400"",
""DateTime"": ""2021-11-16 21:18:37.500"",
""DateTime"": ""2021-11-16 21:18:37.600"",
""DateTime"": ""2021-11-16 21:18:37.700"",
""DateTime"": ""2021-11-16 21:18:37.800"",
""InstrumentID"": ""2424009""
""DateTime"": ""2021-11-16 21:18:37.000"",
""DateTime"": ""2021-11-16 21:18:37.100"",
""DateTime"": ""2021-11-16 21:18:37.200"",
""DateTime"": ""2021-11-16 21:18:37.300"",
""DateTime"": ""2021-11-16 21:18:37.400"",
""DateTime"": ""2021-11-16 21:18:37.500"",
""DateTime"": ""2021-11-16 21:18:37.600"",
""DateTime"": ""2021-11-16 21:18:37.700"",
""DateTime"": ""2021-11-16 21:18:37.800"",