Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update auto.partition() function to recognize Unstructured json #337

Merged
merged 25 commits into from
Mar 8, 2023

Conversation

natygyoon
Copy link
Contributor

unstructured/partition/json.py Outdated Show resolved Hide resolved
Comment on lines 32 to 34
if file_text_whitespace_removed[0] == "[" and file_text_whitespace_removed[-1] == "]":
if len(file_text_whitespace_removed) == 2 or \
(file_text_whitespace_removed[1] == "{" and file_text_whitespace_removed[-2] == "}"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good way to verify if text is indeed parsable as JSON. Consider e.g.:

try:
    unstructured_json = json.loads(file_text)
except json.JSONDecodeError:
    raise ...
return dict_to_elements(unstructured_json)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've originally put these conditions to quickly raise for invalid input format as optimization, since we call json_loads in elements_from_json anyways.

unstructured/partition/json.py Outdated Show resolved Hide resolved
@natygyoon natygyoon requested a review from cragwolfe March 7, 2023 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants