<@U0667DNC02Y> whats the best MetadataValue Way to...
# ask-ai
p
@Scout whats the best MetadataValue Way to preview List or Set values?
s
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.