From 34503dd274fd2742cb54f8da310749687ae26554 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Wed, 2 Jun 2021 21:56:58 +0000 Subject: [PATCH] Guarantee stable output order --- ia-files-xml-to-jsonl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ia-files-xml-to-jsonl b/ia-files-xml-to-jsonl index 28cab3f..7a2a493 100755 --- a/ia-files-xml-to-jsonl +++ b/ia-files-xml-to-jsonl @@ -14,4 +14,8 @@ for file in root: children = {child.tag: child.text for child in file} assert not any(k in children for k in attributes), 'attribute found in children' assert not any(k in attributes for k in children), 'child found in attributes' - print(json.dumps({**attributes, **children})) + assert 'name' in attributes, 'malformed file without name attribute' + o = {'name': attributes['name']} + del attributes['name'] + o.update(sorted({**attributes, **children}.items())) + print(json.dumps(o))