Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B013B200C04 for ; Tue, 24 Jan 2017 12:19:10 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id AE9DF160B4B; Tue, 24 Jan 2017 11:19:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 05291160B3D for ; Tue, 24 Jan 2017 12:19:09 +0100 (CET) Received: (qmail 73942 invoked by uid 500); 24 Jan 2017 11:19:09 -0000 Mailing-List: contact commits-help@ponymail.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ponymail.incubator.apache.org Delivered-To: mailing list commits@ponymail.incubator.apache.org Received: (qmail 73931 invoked by uid 99); 24 Jan 2017 11:19:09 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jan 2017 11:19:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 7FF44C0807 for ; Tue, 24 Jan 2017 11:19:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.218 X-Spam-Level: X-Spam-Status: No, score=-6.218 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id RimrzHbfzd9h for ; Tue, 24 Jan 2017 11:19:07 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id C4B095F296 for ; Tue, 24 Jan 2017 11:19:06 +0000 (UTC) Received: (qmail 73928 invoked by uid 99); 24 Jan 2017 11:19:06 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jan 2017 11:19:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E335DDFA6D; Tue, 24 Jan 2017 11:19:05 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sebb@apache.org To: commits@ponymail.incubator.apache.org Message-Id: <38a5c3df5d704e60bc973870def16472@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-ponymail git commit: Simple script to prettify json output Date: Tue, 24 Jan 2017 11:19:05 +0000 (UTC) archived-at: Tue, 24 Jan 2017 11:19:10 -0000 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 Authored: Tue Jan 24 11:18:52 2017 +0000 Committer: Sebb 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