-
Notifications
You must be signed in to change notification settings - Fork 1
General usage examples
Stache edited this page Jun 7, 2022
·
4 revisions
This is an example on one usage, but of course, it will mainly depends on your needs.
import json
with open("input.json", "r") as json_file:
data = json.load(json_file)Parse the data
from argonodes.parsers import JSONParser
parser = JSONParser()
json_data = parser(data)Create a Tree for exploration
from argonodes.nodes import Tree
tree = Tree(json_data)Play with the Tree
from argonodes.appliers import DistinctValues
distinct_values = DistinctValues()
distinct_values(tree)
# or
tree.apply(distinct_values)Create a Model from the Tree
from argonodes.models import Model
model = Model(name="My model", tree=tree)Filter the Model
from argonodes.filters import Filter
keep_placeVisit_only = Filter(model, paths="$.timelineObjects[*].placeVisit")
keep_placeVisit_only(model)
# or
model.apply(keep_placeVisit_only)Export the Model
from argonodes.exporters import JSONExporter
exporter = JSONExporter()
json_out = model.export(exporter)
# or
json_out = exporter(model)with open("input.json", "r") as json_file:
json_out = Model(Tree(json.load(json_file))).export(exporter)