Amazon Textract Response to CSV export tables and extract key-value
pairs in form documents from JSON
returned by Amazon Textract into a comma-separated values (CSV) file.
This module work both with ESM and CommonJs
import { writeTables } from "amazon-textract-response-tocsv";
const analyze_document_text = async () => {
try {
const analyzeDoc = new AnalyzeDocumentCommand(params);
const response = await textractClient.send(analyzeDoc);
//call writeTables with the response
await writeTables(response);
} catch (err) {
console.log("Error", err);
}
};
The writeTables function of Amazon Textract Response to CSV take one parameters the
JSON returned by Amazon Textract.
And then exports data in an file named : tables_output.csv
import { writeTables, writeKeyValuePair } from "amazon-textract-response-tocsv";
await writeTables(response);
const {
writeTables,
writeKeyValuePair,
} = require("amazon-textract-response-tocsv");
await writeTables(response);
import { writeKeyValuePair } from "amazon-textract-response-tocsv";
const analyze_document_text = async () => {
try {
const analyzeDoc = new AnalyzeDocumentCommand(params);
const response = await textractClient.send(analyzeDoc);
//call writeKeyValuePair with the response
await writeKeyValuePair(response);
} catch (err) {
console.log("Error", err);
}
};
The writeKeyValuePair function just like the writeTables function of Amazon Textract Response to CSV takes one parameters the JSON
returned by Amazon Textract.
The only difference is that the exported file will be named : key_value_output.csv
await writeKeyValuePair(response);
This project is released under the MIT License ✔