Skip to content

Instantly share code, notes, and snippets.

@dmontagu
Last active May 2, 2024 15:55
Show Gist options
  • Save dmontagu/a5445fa817d71f0f4969f6fdbad38a8d to your computer and use it in GitHub Desktop.
Save dmontagu/a5445fa817d71f0f4969f6fdbad38a8d to your computer and use it in GitHub Desktop.
from pydantic_core import from_json

partial_json_data = '["aa", "bb", "c'  # (1)!

try:
    result = from_json(partial_json_data, allow_partial=False)
except ValueError as e:
    print(e)  # (2)!
    #> EOF while parsing a string at line 1 column 15

result = from_json(partial_json_data, allow_partial=True)
print(result)  # (3)!
#> ['aa', 'bb']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment