21-08-19 09:01 PM
I'm using Blue Prism to call the Microsoft Computer Vision API to recognize text from a PDF.
After getting the JSON response, Blue Prism transforms it into a Collection (DataTable) using either the JSON Utility from Blue Prism, or the Action Provided on the Microsoft Computer Vision skill: Get Read Operation Response.
Problem: Blue Prism is unable parse the JSON text into a Collection in certain cases due to a data type error.
Can someone sugest a code to convert this type of JSON structure into a DataTable which Blue Prism can read?
I have attached pastebin links for the 2 JSON (Body is limited to 30000 characters, can't copy them here).
READABLE in Blue Prism (contains special characters !'#$%&/()''):
NOT READABLE in Blue Prism:
Blue Prism gives the following errors:
Using 'Get Read Operation Response' action:
Internal : Unexpected error Data Type mismatch in array: Element '3' has type instead of expected type 'System.Double'
Using 'JSON Utility from Blue Prism':
Internal : Could not execute code stage because exception thrown by code stage: Data Type mismatch in array
I tried to parse the nested JSON into a datatable by 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, just parse the JSON directly to the data table by pointing to the property recognitionResults.
Without classes:
DataSet ds = JObject.Parse(json_txt)['recognitionResults'].ToObject();
With 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; }
}
Here is how the nested collection should look like in Blue Prism: Blue Prism Nested Response Collection
--------------------------------------------------22-08-19 06:29 AM