in api-samples/Extraction.Json/SampleProgram.cs [15:85]
private static void Main(string[] args)
{
var jsonText = @"[
{""person"": {
""name"": {
""first"": ""Carrie"",
""last"": ""Dodson""
},
""address"": ""1 Microsoft Way"",
""phone number"": []
}
},
{""person"": {
""name"": {
""first"": ""Leonard"",
""last"": ""Robledo""
},
""phone number"": [
""123-4567-890"",
""456-7890-123"",
""789-0123-456""
]}
}
]";
// Option 1: Joining Inner Arrays
// Learn a program with the constraint to flatten the entire document.
var session = new Session();
session.Inputs.Add(jsonText);
session.Constraints.Add(JoinAllArrays.Instance);
Program program = session.Learn();
if (program == null)
{
Console.WriteLine("Fail to learn a program!");
return;
}
// Serialize and deserialize the program
var programText = program.Serialize();
program = Loader.Instance.Load(programText);
if (program == null)
{
Console.WriteLine("Fail to load deserialized program!");
return;
}
// Run the program and obtain the table
ITable<string> table = program.Run(jsonText);
Console.WriteLine("Joining Inner Array Table!");
PrintTable(table);
// Option 2: No Joining Inner Arrays
var noJoinSession = new Session();
noJoinSession.Inputs.Add(jsonText);
Program noJoinProgram = noJoinSession.Learn();
if (noJoinProgram == null)
{
Console.WriteLine("Fail to learn a program!");
return;
}
// Run the program and obtain the table output
table = noJoinProgram.Run(jsonText);
Console.WriteLine("No Joining Inner Array Table!");
PrintTable(table);
Console.WriteLine("Done.");
}