question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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]. image

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:closed
  • Created a year ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
catalinaperaltacommented, Apr 20, 2022

Anytime! 😃 I will close this issue now. Feel free to report new issues in the future.

0reactions
bostdiekcommented, Apr 20, 2022

Ah perfect, thank you so much for your help!

On Wed, Apr 20, 2022 at 2:30 PM catalinaperalta @.***> wrote:

Hi @bostdiek https://github.com/bostdiek, the reason there’s an error with the code above is that on the last two lines of the code there’s a wb instead of just a w to write the given string to the output file. With the wb then it’s expecting a bytes-like object and to_dict() returns a str .

— Reply to this email directly, view it on GitHub https://github.com/Azure/azure-sdk-for-python/issues/24085#issuecomment-1104292395, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPQFP74C55E4SORIVXJZTDVGBEK7ANCNFSM5TZXSMKQ . You are receiving this because you were mentioned.Message ID: @.***>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invoice data extraction – Form Recognizer - Azure Applied AI ...
Automate invoice data extraction with Form Recognizer's invoice model to extract ... and returns a structured JSON data representation.
Read more >
How to convert json into data type that is supported by Azure ...
I'd like to convert a json into the data type that is supported by Azure Form Recognizer. I'm able to convert the data...
Read more >
Azure SDK for JavaScript (February 2022)
In the prebuilt-invoice model, several numeric fields that represented amounts of money have been changed to a designated "currency" type.
Read more >
Receipt database with OCR scan - IS MUNI
8.2 Operational costs of using Form Recognizer compared to ... did not keep their receipt or put it among all the other receipts...
Read more >
Java - CodeProject
This tutorial will introduce the basics needed to use RequireJS to build modularized web applications with JavaScript. Weather or Not. 12 Jun 2020...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found