From 681da142c548e34dfe29d67cb8f32cef8bf047da Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Thu, 5 Dec 2019 00:01:15 +0000 Subject: [PATCH] Renderers: Split JSON output into JSON and JSONL --- volatility/cli/text_renderer.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/volatility/cli/text_renderer.py b/volatility/cli/text_renderer.py index 4656fb019..4c38b5832 100644 --- a/volatility/cli/text_renderer.py +++ b/volatility/cli/text_renderer.py @@ -301,6 +301,10 @@ class JsonRenderer(CLIRenderer): def get_render_options(self) -> List[RenderOption]: pass + def output_result(self, outfd, result): + """Outputs the JSON data to a file in a particular format""" + outfd.write(json.dumps(result, indent = 2, sort_keys = True)) + def render(self, grid: interfaces.renderers.TreeGrid): outfd = sys.stdout @@ -334,4 +338,14 @@ class JsonRenderer(CLIRenderer): else: grid.visit(node = None, function = visitor, initial_accumulator = final_output) - outfd.write(json.dumps(final_output[1], indent = 2, sort_keys = True)) + self.output_result(outfd, final_output[1]) + + +class JsonLinesRenderer(JsonRenderer): + name = 'JSONL' + + def output_result(self, outfd, result): + """Outputs the JSON results as JSON lines""" + for line in result: + outfd.write(json.dumps(line, sort_keys = True)) + outfd.write("\n")