cancel
Showing results for 
Search instead for 
Did you mean: 

NewtonSoft Deserialize nested JSON

please help a doomed soul. I don't understand how to cast each part of the nested json into a datatable.

I tried creating the public classes using the tool provided at json2csharp.com, and then point to them and write to the data table.

I also tried by not creating the classes and just convert json directly to the data table.

With classes:

DataSet ds = JObject.Parse(json_txt)['recognitionResults'].ToObject();

Without classes:

DataTable dt = (DataTable)JsonConvert.DeserializeObject(json_txt, (typeof(DataTable)));

Classes:

public class Word
{
    public List<double> boundingBox { get; set; }
    public string text { get; set; }
    public string confidence { get; set; }
}

public class Line
{
    public List<double> boundingBox { get; set; }
    public string text { get; set; }
    public List<Word> words { get; set; }
}

public class RecognitionResult
{
    public int page { get; set; }
    public double clockwiseOrientation { get; set; }
    public double width { get; set; }
    public double height { get; set; }
    public string unit { get; set; }
    public List<Line> lines { get; set; }
}

public class RootObject
{
    public string status { get; set; }
    public List<RecognitionResult> recognitionResults { get; set; }
}

JSON txt:

pastebin.com/yBVrLveq

For context:

I used the Microsoft Computer Vision API to recognize text from a PDF.

If is not possible to map each property of the json file into the datatable, it would be fine to have a table like:

'page 0' : 'lines' 'page 1' : 'lines'

Each set of 'lines' contains a variable number of lines. That's what I mean by nested.

--------------------------------------------------
Disclaimer: This content was auto-posted from Stackoverflow. The original Stackoverflow question is here Stackoverflow Post, posted by David Vizcaino.
Hi  I am a Digital Worker. Please check out my profile to learn more about what I do!
1 BEST ANSWER

Helpful Answers

david.flores
Staff
Staff
Hello, 

To accomplish this I used the OCR Response (collection) from the MS vision skill output then looped through the Nested collections the JSON created into sub-collections until i was able to get to the text that I needed then contactinated the text into a Text Data Item. 
6095.png
Hopefully this help you get the data you looking for. 


------------------------------
Regards,

David Flores
Sr. Product Consultant
blue prism
------------------------------
Regards, [FirstName] [LastName] [JobTitle] [CompanyName]

View answer in original post

1 REPLY 1

david.flores
Staff
Staff
Hello, 

To accomplish this I used the OCR Response (collection) from the MS vision skill output then looped through the Nested collections the JSON created into sub-collections until i was able to get to the text that I needed then contactinated the text into a Text Data Item. 
6095.png
Hopefully this help you get the data you looking for. 


------------------------------
Regards,

David Flores
Sr. Product Consultant
blue prism
------------------------------
Regards, [FirstName] [LastName] [JobTitle] [CompanyName]