Skip to content

Commit 565b709

Browse files
committed
add json string parsing to ValidateAdheresToSchema
1 parent dad6100 commit 565b709

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

airbyte_cdk/sources/declarative/validators/validate_adheres_to_schema.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
from dataclasses import dataclass
6+
import json
67
from typing import Any, Mapping
78

89
import jsonschema
@@ -25,6 +26,13 @@ def validate(self, value: Any) -> None:
2526
:param value: The value to validate
2627
:raises ValueError: If the value does not adhere to the schema
2728
"""
29+
30+
if isinstance(value, str):
31+
try:
32+
value = json.loads(value)
33+
except json.JSONDecodeError as e:
34+
raise ValueError(f"Invalid JSON string: {value}") from e
35+
2836
try:
2937
jsonschema.validate(instance=value, schema=self.schema)
3038
except jsonschema.ValidationError as e:

0 commit comments

Comments
 (0)