Parsing JSON lines
... or how to integrate tools that output JSON lines.
One-to-one mapping
Example:
mytool -jsonl -u mytarget.com
{"url": "https://mytarget.com/api", "status": 200, {"details": {"ct": "application/json"}}
{"url": "https://mytarget.com/api/metrics", "status": 403, "details": {}}from secator.decorators import task
from secator.runners import Command
from secator.output_types import Url
from secator.serializers import JSONSerializer
from secator.definitions import URL, STATUS_CODE, CONTENT_TYPE
@task()
class mytool(Command):
input_flag = '-u'
json_flag = '-jsonl'
output_types = [Url]
item_loaders = [JSONSerializer()]
output_map = {
Url: {
URL: 'url',
STATUS_CODE: 'status',
CONTENT_TYPE: lambda x: x['details'].get('ct', '')
}
}
One-to-many
Example:
Last updated