ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject incubator-ponymail git commit: Simple script to prettify json output
Date Tue, 24 Jan 2017 11:19:05 GMT
Repository: incubator-ponymail
Updated Branches:
  refs/heads/master 0ee200819 -> c3bfd04bd


Simple script to prettify json output

Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/c3bfd04b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/c3bfd04b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/c3bfd04b

Branch: refs/heads/master
Commit: c3bfd04bd5ddeb49b52b4d148bc815b650c30518
Parents: 0ee2008
Author: Sebb <sebb@apache.org>
Authored: Tue Jan 24 11:18:52 2017 +0000
Committer: Sebb <sebb@apache.org>
Committed: Tue Jan 24 11:18:52 2017 +0000

----------------------------------------------------------------------
 tools/json_tidy.py | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/c3bfd04b/tools/json_tidy.py
----------------------------------------------------------------------
diff --git a/tools/json_tidy.py b/tools/json_tidy.py
new file mode 100755
index 0000000..3c92b08
--- /dev/null
+++ b/tools/json_tidy.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+ Prettify json: indent, sort
+ Can also drop keys that aren't wanted, e.g. the debug array, to make diffs easier
+"""
+
+import sys
+import json
+import argparse
+
+parser = argparse.ArgumentParser()
+parser.add_argument("--indent", type=int, help="Indentation to use for the output file (default
1)", default=1)
+parser.add_argument("--drop", help="Comma-separated list of top-level keys to drop (e.g.
debug,took)", default='')
+
+args = parser.parse_args()
+
+input = json.loads(sys.stdin.read())
+for key in args.drop.split(','):
+    try:
+        del input[key]
+    except KeyError:
+        pass
+
+json.dump(input, sys.stdout, indent=args.indent, sort_keys=True)
+print("") # EOL at EOF


Mime
View raw message