json_artifact
Adapted from the Griptape AI Framework documentation.
Json = Union[dict[str, 'Json'], list['Json'], str, int, float, bool, None]
module-attribute
Bases:
BaseArtifact
Attributes
Name | Type | Description |
---|---|---|
value | Json | The JSON data. Values will automatically be converted to a JSON-compatible format. |
Source Code in griptape/artifacts/json_artifact.py
@define class JsonArtifact(BaseArtifact): """Stores JSON data. Attributes: value: The JSON data. Values will automatically be converted to a JSON-compatible format. """ value: Json = field(converter=lambda value: JsonArtifact.value_to_json(value), metadata={"serializable": True}) @classmethod def value_to_json(cls, value: Any) -> Json: if isinstance(value, str): return json.loads(value) return json.loads(json.dumps(value)) def to_text(self) -> str: return json.dumps(self.value)
value = field(converter=lambda value: JsonArtifact.value_to_json(value), metadata={'serializable': True})
class-attribute instance-attribute
to_text()
Source Code in griptape/artifacts/json_artifact.py
def to_text(self) -> str: return json.dumps(self.value)
value_to_json(value)classmethod
Source Code in griptape/artifacts/json_artifact.py
@classmethod def value_to_json(cls, value: Any) -> Json: if isinstance(value, str): return json.loads(value) return json.loads(json.dumps(value))
Could this page be better? Report a problem or suggest an addition!