Emmanuel Rambeau
10/20/2024, 10:30 PMMarvin
10/20/2024, 10:31 PMjson.dumps()
.
- Example:
python
import json
from prefect import Variables
my_json = {"test": "Hello world"}
serialized_json = json.dumps(my_json)
Variables.set(name="test", value=serialized_json)
2. Retrieve and Deserialize JSON from a Prefect Variable:
- When retrieving the variable, convert the string back into a JSON object using json.loads()
.
- Example:
python
import json
from prefect import Variables
serialized_json = Variables.get("test")
my_json = json.loads(serialized_json)
print(my_json) # Outputs: {'test': 'Hello world'}
By storing JSON data as a string, you ensure compatibility with the Prefect variable system, while still maintaining structured data that can be easily deserialized back into Python objects.
You can find more details about variables in Prefect 3.x on this documentation page.Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by