Been experimenting with Azure Form Recognizer to structure PDF documents. The service returns key/value pairs as shown below:
I need to be able to extract the key: “Number” and corresponding value: “RITM0041763” from this array. This particular file has a plethora of these key/value pairs from the document. I have traditionally deserialized JSON files I created manually using the Deserialize JSON activity and then used 'JSON(“Number”) but due to the nested nature of this file, it will not work.
Can you post the JSON you have so that I will try and get back to you?
Uploaded below - if you have a solution in mind which is easy to change (ex. the key values are different) that would be largely helpful as I need to reconfigure this for multiple use cases.
RITM041763_Scrubbed.json (51.4 KB)
You want to get only the first number or all the values of key in the JSON @joshgregory10
I want to be able to write in a key name (ex. Number) and return the corresponding value (element) in the JSON array.
Any ideas on a solution? I have deserialized the JSON to a JObject and tried to pull values using a for each loop but it appears more complex…
I just started looking into it. Do you mind sharing how did you setup the Form Recognizer? I had found and installed a “Microsoft.Azure.CognitiveServices.FormRecognizer” package, but can’t figure out how to use it.
Thank you in advance,
Here is the package for your reference, but you need to apply some logic inside so that you can check for the text to get the number @joshgregory10
json1.xaml (77.6 KB)
Hi Alex - that is the Nu Get package for the C# SDK. It will not have activities within UiPath, I am working on creating custom activities for this.
I had someone from Microsoft help me parse the key/value pairs however it is in Python, not VB.NET so I cannot translate it to UiPath well. Can someone take a look and see what they can do? See below:
response_file = “response.json”
Specify the list of keys to be reported.
keys = set([“Address:”])
with open(response_file, mode = “r”, encoding = “utf-8”) as f:
data = json.load(f)
# Loop over all pages in the document.
for page in data[“pages”]:
# Loop over all key/value pairs in the page.
for kvp in page[“keyValuePairs”]:
key_txt = " ".join([x[“text”] for x in kvp[“key”]])
# Report only the pre-specified subset of keys.
if key_txt in keys:
print(“key: %s” % key_txt)
vals = [x[“text”] for x in kvp[“value”]]
print(“value: %s” % " ".join(vals))
I tried building a nested for-each loop but the bolded line I included is not translating into VB within UiPath.
RITM041763_Scrubbed.json (51.4 KB)
You can run the python code also in UiPath, have you checked that.
Install UiPath.Python.Activities and just give the file path and the python directory path
Can I load variables after running the Python scripts?
Can you explain a bit more?
As per my understanding, You can return the result from the python code and get it back to uipath workflow, then use it further
I will need to extract key/value pairs using Python code and then load those key value pairs to UiPath variables.
For instance, say I pulled 3 kvp from the document. I want to assign those 3 kvp values to 3 variables in the workflow:
Kvp1 = number
Kvp2 = hareesh
Kvp3 = madasi
It was my understanding the Python activities would only execute a script and not permit data flow between the script and the workflow.
I’m using the code to compare two images for my internal purpose and I’m getting the array of results where there is a mismatch in data @joshgregory10
We can get the values
Would you mind attaching XAML?
Sorry, the code has all my credentials and some confidential data.
But no worries, as you are constructing a string in the print statement, just change it as return statement and capture it as the string in uipath workflow, but here is the code for your reference. Sure you will understand this
PyhtonCode.zip (3.2 KB)
Worked like a charm! Had to make some tweaks to my .PY file that Microsoft provided (converted it to a function) so that I could pull data out of it back to the workflow. Other than that - THANKS!
You can post the query at any time, would be happy to help