FormRecognizer Prebuilt Invoice Currency is not JSON serializable
See original GitHub issue- FormRecognizer:
- API Version 2022-01-30
- Azure Machine Learning compute instance (linux):
- Python Version: 3.9
Describe the bug Running the invoice model with async following the example on https://github.com/Azure/azure-sdk-for-python/blob/5eb462494af1be848453f05fda0558208431e1aa/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/async_samples/sample_analyze_invoices_async.py.
Then, I am trying to save the results as a json using the example provided in https://github.com/Azure/azure-sdk-for-python/blob/5eb462494af1be848453f05fda0558208431e1aa/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/async_samples/sample_convert_to_and_from_dict_async.py
i.e.
# convert the received model to a dictionary
analyze_result_dict = result.to_dict()
# save the dictionary as JSON content in a JSON file, use the AzureJSONEncoder
# to help make types, such as dates, JSON serializable
# NOTE: AzureJSONEncoder is only available with azure.core>=1.18.0.
with open('data.json', 'w') as f:
json.dump(analyze_result_dict, f, cls=AzureJSONEncoder)
However, when I do this, I get the following error [TypeError: Object of type CurrencyValue is not JSON serializable].
I tried adding a default to the json.dump
json.dump(analyze_result_dict, f, indent=2, cls=AzureJSONEncoder, default=lambda x: x.__dict__)
but that then broke the datetime outputs.
How are am I supposed to save the outputs of the Form Recognizer invoice model?
Issue Analytics
- State:
- Created a year ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
Anytime! 😃 I will close this issue now. Feel free to report new issues in the future.
Ah perfect, thank you so much for your help!
On Wed, Apr 20, 2022 at 2:30 PM catalinaperalta @.***> wrote: