Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Extraction of MISP tags from machinetag.json in a list for Dataturks
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import logging.config
# ==================== ------ STD LIBRARIES ------- ====================
import pathlib
import json
# ==================== ------ PREPARATION ------- ====================
def extract(path : pathlib.Path):
tmp_json = load_json(path)
for val in tmp_json["values"]:
for entry in val["entry"]:
tmp_str = tmp_json["namespace"] + ":" + val["predicate"] + '="' + entry["value"] + '",'
def load_json(file_path: pathlib.Path):
logger = logging.getLogger()
# !! : json.load() is for loading a file. json.loads() works with strings.
# json.loads will load a json string into a python dict, json.dumps will dump a python dict to a json string,
if file_path.is_file():
# We have a valid file to load
with open(str(file_path.resolve())) as json_file:
data = json.load(json_file)
logger.debug(f"File loaded from {file_path}.")
raise Exception(f"Cannot load the provided path to json : path is not a valid file {file_path}")
return data
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment