-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFormAnalyzer_ExtractColumn_FromJSON.py
More file actions
32 lines (24 loc) · 1.26 KB
/
FormAnalyzer_ExtractColumn_FromJSON.py
File metadata and controls
32 lines (24 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#sample code for iterating through a section of the JSON returned by Form Recognizer to get to the contents of tables in the documents
import json
jsonfilename = 'Tesco_Receipt_Example.json'
with open(jsonfilename, "r") as read_file:
receipt = json.load(read_file)
def getColumnEntries (jsonDict, headertext):
columnentries = []
for page in jsonDict['pages']:
for table in page['tables']:
#FOR DEBUG print ("Table ids are: " + table.get('id'))
for column in table['columns']:
#FOR DEBUG print(column.get('header')[0].get('text'))
for header in column['header']:
#FOR DEBUG print(header.get('text'))
if header.get('text') == headertext:
#FOR DEBUG print(column.get('header'))
for entry in column['entries']:
#FOR DEBUG print(entry)
for entryitem in entry:
#FOR DEBUG print(entryitem.get('text'))
columnentries.append(entryitem.get('text'))
return columnentries
print(getColumnEntries(receipt, 'Product'))
# Options for the Tesco Receipts are Quantity, Product, Total