Task
You want to get, manipulate, and print or save, the contents of the document elements and metadata from the processed data that Unstructured returns.Approach
Each element in the document elements contains fields for that element’s type, its ID, the extracted text, and associated metadata. The programmatic approach you take to get these document elements will depend on which SDK you use:Python SDK
Python SDK
For the Unstructured Python SDK, calling an You can use standard Python list operations on this list.You can also use standard Python looping techniques on this list to access each element in this list.To work with an individual element’s contents, you can use standard dictionary operations on the element.For example:To serialize this list as JSON, you can:
UnstructuredClient object’s general.partition_async method returns a PartitionResponse object.This PartitionResponse object’s elements variable contains a list of key-value dictionaries (List[Dict[str, Any]]). For example:Python
Python
- Use the
elements_from_dictsfunction to convert the list of key-value dictionaries (Iterable[Dict[str, Any]]) into a list of elements (Iterable[Element]). - Use the
elements_to_jsonfunction to convert the list of elements into a JSON-formatted string and then print or save that string.
Python
JavaScript/TypeScript SDK
JavaScript/TypeScript SDK
For the Unstructured JavaScript/TypeScript SDK, calling an You can use standard Array operations on this array.You can also use standard To serialize this list as JSON, you can use the standard JSON.stringify function to serialize it to JSON-formatted string and the Node.js fs.WriteFileSync function to save it as a file. For example:
UnstructuredClient object’s general.partition method returns a Promise<PartitionResponse> object.This PartitionResponse object’s elements property contains an Array of string-value objects ({ [k: string]: any; }[]). For example:TypeScript
Array techniques such as forEach to access each object in this array. For example:TypeScript
TypeScript

