https://dagster.io/ logo
#ask-ai
Title
# ask-ai
p

Paul Herzog

02/21/2024, 12:52 PM
@Scout whats the best MetadataValue Way to preview List or Set values?
s

Scout

02/21/2024, 12:52 PM
The best way to preview list or set values using
MetadataValue
in Dagster would be to convert them into a JSON format using
MetadataValue.json
. This method allows you to attach JSON-serializable data to your metadata, which can be easily used to represent lists or sets. Here's an example from the documentation on how to use `MetadataValue.json`:
Copy code
python @op def emit_metadata(context):     my_list = [1, 2, 3]     my_set = {"a", "b", "c"}     yield AssetMaterialization(         asset_key="my_dataset",         metadata={             "my_list": MetadataValue.json(list(my_list)),  # Convert set to list for JSON serialization             "my_set": MetadataValue.json(list(my_set))     # Convert set to list for JSON serialization         },     )
In this example, both the list and the set are converted to lists (since sets are not JSON serializable) and then passed to
MetadataValue.json
to be included in the metadata. This way, you can preview the values in the Dagster UI or any other tooling that consumes this metadata.