json_artifact#
Json = Union[dict[str, 'Json'], list['Json'], str, int, float, bool, None]module-attribute
Bases: BaseArtifact “)
Attributes#
Name |
Type |
Description |
|---|---|---|
<a href="json_artifact.mdx#griptape.artifacts.json_artifact.JsonArtifact.value" title="value = field(converter=lambda value: JsonArtifact.value_to_json(value), metadata={'serializable': True}) class-attribute instance-attribute (griptape.artifacts.json_artifact.JsonArtifact.value)"><code class="language-python">value</code></a> |
<a href="json_artifact.mdx#griptape.artifacts.json_artifact.Json" title="Json = Union[dict[str, 'Json'], list['Json'], str, int, float, bool, None] module-attribute (griptape.artifacts.json_artifact.Json)"><code class="language-python">Json</code></a> |
The JSON data. Values will automatically be converted to a JSON-compatible format.<br/> |
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))