From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYAbJ-0000ar-66 for qemu-devel@nongnu.org; Tue, 23 Feb 2016 05:53:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYAbF-0001pQ-QJ for qemu-devel@nongnu.org; Tue, 23 Feb 2016 05:53:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57861) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYAbF-0001pJ-BV for qemu-devel@nongnu.org; Tue, 23 Feb 2016 05:53:49 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id EB7B38E3D5 for ; Tue, 23 Feb 2016 10:53:48 +0000 (UTC) Date: Tue, 23 Feb 2016 10:53:45 +0000 From: "Daniel P. Berrange" Message-ID: <20160223105345.GD22780@redhat.com> References: <1456160567-18072-1-git-send-email-berrange@redhat.com> <56CB855B.1030906@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <56CB855B.1030906@redhat.com> Subject: Re: [Qemu-devel] [PATCH] qmp-shell: fix pretty printing of JSON responses Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Luiz Capitulino , qemu-devel@nongnu.org, Markus Armbruster On Mon, Feb 22, 2016 at 03:02:03PM -0700, Eric Blake wrote: > On 02/22/2016 10:02 AM, Daniel P. Berrange wrote: > > Pretty printing of JSON responses is important to be able > > to understand large responses from query commands in > > particular, eg > > > > (QEMU) query-chardev > > { u'return': [ { u'filename': u'vc', > > u'frontend-open': False, > > u'label': u'parallel0'}, > > { u'filename': u'vc', > > u'frontend-open': True, > > u'label': u'serial0'}, > > { u'filename': u'unix:/tmp/qemp,server', > > u'frontend-open': True, > > u'label': u'compat_monitor0'}]} > > > > Unfortunately this was broken during the addition of > > the verbose flag in > > > > commit 1ceca07e48ead0dd2e41576c81d40e6a91cafefd > > Author: John Snow > > Date: Wed Apr 29 15:14:04 2015 -0400 > > > > scripts: qmp-shell: Add verbose flag > > > > This is because that change turned the python data > > structure into a formatted JSON string before the > > pretty print was given it. So we're just pretty > > printing a string, which is a no-op. > > > > This fixes pretty printing of the command responses > > and as an added benefit it will also pretty print > > command arguments in verbose mode > > > > (QEMU) object-add qom-type=secret id=sec0 props={"data":"123456"} > > { 'arguments': { 'id': 'sec0', > > 'props': { u'data': u'123456'}, > > 'qom-type': 'secret'}, > > 'execute': 'object-add'} > > { u'return': { }} > > That's an odd mix of regular and Unicode strings. Any ideas why it is > happening? But the patch is a strict improvement, so: It is todo with the way qmp-shell parses the command line. The qom-type and id arguments it just parses directly, but the last props argument it gets by using json.loads() which returns unicode strings. I realized we can avoid this issue and improve output style by not pretty printing a python data struture, and instead telling the json formatter to pretty print its output. So I've sent a v2 that does that Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|