Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert "google.cloud.documentai_v1.types.document" object to json

I am using Google Cloud Document AI's Invoice Parser. API response is google.cloud.documentai_v1.types.Document object. I tried to write below approaches for converting it to JSON but nothing works:

  • json.dumps() but it gives JSONDecodeError
  • google.cloud.documentai_v1.Document.to_json()
like image 206
kushagra Avatar asked Sep 18 '25 12:09

kushagra


1 Answers

You should be able to get the JSON with the to_json method you mentioned, but you have to pass the document you want to get as a JSON file, such as

google.cloud.documentai_v1.Document.to_json(my_document)

which will output the JSON file.

like image 159
bernatj Avatar answered Sep 21 '25 03:09

bernatj