Hi @Harsh Khewal,
Thank you for reaching out to us with your query about saving the output of Azure's Document Intelligence as a JSON file locally. I'd be happy to help you with that.
Here is an example code that uses the Azure Form Recognizer SDK to analyze a document and saved the output as a JSON file:
from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient
import json
# Your Azure Form Recognizer endpoint and API key
endpoint = "<YOUR_ENDPOINT>"
key = "<YOUR_API_KEY>"
# Initialize the DocumentAnalysisClient
credential = AzureKeyCredential(key)
document_analysis_client = DocumentAnalysisClient(endpoint, credential)
# The local file path to the document you want to analyze
document_path = r"<path/to/your/document.pdf>"
# Submitting the document for analysis
with open(document_path, "rb") as f:
analyze_result = document_analysis_client.begin_analyze_document("prebuilt-layout", document=f).result()
# Convert the analysis result to JSON
result_json = analyze_result.to_dict()
# Save the JSON to a local file
output_json_path = "output.json"
with open(output_json_path, "w") as output_file:
json.dump(result_json, output_file, indent=4)
print("Analysis result saved to:", output_json_path)
I hope this helps. Thank you.