I'm working on converting JSON files into CSV using ChoETL .
So far the converting is working fine!
My code is :
var sampleJson = File.ReadAllText(@"C:\cpi\log\V510ResultsInfo\cpi001.json");
StringBuilder stringBuilder = new StringBuilder();
using (var machineheight = ChoJSONReader.LoadText(sampleJson).WithJSONPath("$..devices"))
{
using (var w = new ChoCSVWriter(stringBuilder).WithFirstLineHeader()
.Configure(c => c.MaxScanRows = 1)
.Configure(c => c.ThrowAndStopOnMissingField = false))
{
w.Write(machineheight);
}
}
File.WriteAllText(@"C:\cpi\log\V510ResultsInfo\convertedjson.csv", stringBuilder.ToString());
What this does is that it basically just converts everything (the whole json file). But I'm looking into something more specific. Something in the 6th node to be exact.
so far :
("$..devices")
is working for the 1st-3rd node.. But my "actual_Height(um)" is the 6th node :
"v510_results" - "devices" - "details" - "roi" - "display" - "actual_Height(um)"
I tried :
("$..actual_Height(um)")
and it's not working..
I feel like the problem is at :
using (var w = new ChoCSVWriter(stringBuilder).WithFirstLineHeader()
But i can't seem to fix it..
Could really use some help T_T
What I have tried:
var sampleJson = File.ReadAllText(@"C:\cpi\log\V510ResultsInfo\cpi001.json");
StringBuilder stringBuilder = new StringBuilder();
using (var machineheight = ChoJSONReader.LoadText(sampleJson).WithJSONPath("$..devices"))
{
using (var w = new ChoCSVWriter(stringBuilder).WithFirstLineHeader()
.Configure(c => c.MaxScanRows = 1)
.Configure(c => c.ThrowAndStopOnMissingField = false))
{
w.Write(machineheight);
}
}
File.WriteAllText(@"C:\cpi\log\V510ResultsInfo\convertedjson.csv", stringBuilder.ToString());