Load and save data
Colander
Load from JSON file
To load a Colander feed from a JSON file, call the method
load()
of
ColanderFeed
:
import json
from colander_data_converter.base.models import ColanderFeed
with open("path/to/colander_feed.json", "r") as f:
raw = json.load(f)
feed = ColanderFeed.load(raw)
# 'feed' is now a ColanderFeed object
Save to JSON file
To save a Colander feed to a JSON file, use model_dump_json()
to convert the feed to
a Python dict
and save it into the destination file in JSON format:
import json
# 'feed' is a ColanderFeed object
feed.unlink_references()
with open("path/to/output_colander_feed.json", "w") as f:
f.write(feed.model_dump_json(indent=2))
Threatr
Load from JSON file
To load a Threatr feed from a JSON file, call the method
load()
of
ThreatrFeed
:
import json
from colander_data_converter.converters.threatr.models import ThreatrFeed
with open("path/to/threatr_feed.json", "r") as f:
raw = json.load(f)
feed = ThreatrFeed.load(raw)
# 'feed' is now a ThreatrFeed object
Save to JSON file
To save a Threatr feed to a JSON file, use model_dump_json()
to convert the feed to
a Python dict
and save it into the destination file in JSON format:
# 'feed' is a ThreatrFeed object
feed.unlink_references()
with open("path/to/output_threatr_feed.json", "w") as f:
f.write(feed.model_dump_json(indent=2))