From nobody Mon Feb 9 07:38:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149856764789582.33977213214985; Tue, 27 Jun 2017 05:47:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91E29104D5; Tue, 27 Jun 2017 12:47:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B66F83FDB; Tue, 27 Jun 2017 12:47:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 064F33FAE1; Tue, 27 Jun 2017 12:47:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RClJqH023845 for ; Tue, 27 Jun 2017 08:47:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9B8648A78C; Tue, 27 Jun 2017 12:47:19 +0000 (UTC) Received: from andariel.redhat.com (ovpn-204-24.brq.redhat.com [10.40.204.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 795738A78F; Tue, 27 Jun 2017 12:47:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 91E29104D5 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 91E29104D5 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 14:46:48 +0200 Message-Id: <1f59c9bbf21a89a3850db1cef96c036ec53ff980.1498567512.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 7/9] util: json: Recursively deflatten objects virJSONValueObjectDeflatten X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 27 Jun 2017 12:47:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If a value of the first level object contains more objects needing deflattening which would be wrapped in an actual object the function would not recurse into them. By this simple addition we can fully deflatten the objects. Reviewed-by: John Ferlan --- src/util/virjson.c | 8 +++++++- tests/virjsondata/deflatten-nested-out.json | 32 +++++++++++++++++++------= ---- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 635b78e3a..0c7beafab 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1981,7 +1981,13 @@ virJSONValueObjectDeflattenWorker(const char *key, /* non-nested keys only need to be copied */ if (!strchr(key, '.')) { - if (!(newval =3D virJSONValueCopy(value))) + + if (virJSONValueIsObject(value)) + newval =3D virJSONValueObjectDeflatten(value); + else + newval =3D virJSONValueCopy(value); + + if (!newval) return -1; if (virJSONValueObjectHasKey(retobj, key)) { diff --git a/tests/virjsondata/deflatten-nested-out.json b/tests/virjsondat= a/deflatten-nested-out.json index acdcd1fc8..f23ed8fd5 100644 --- a/tests/virjsondata/deflatten-nested-out.json +++ b/tests/virjsondata/deflatten-nested-out.json @@ -1,17 +1,27 @@ { "file": { "nest": { - "even.objects": "can", - "even.contain": "some", - "even.more": { - "deeply.nested": "objects", - "deeply.needing": "deflattening", - "deeply.some.even": "more", - "deeply.some.than": { - "others.thought.was": "even", - "others.thought.completely": "necessary" - }, - "perhaps": "flat value" + "even": { + "objects": "can", + "contain": "some", + "more": { + "deeply": { + "nested": "objects", + "needing": "deflattening", + "some": { + "even": "more", + "than": { + "others": { + "thought": { + "was": "even", + "completely": "necessary" + } + } + } + } + }, + "perhaps": "flat value" + } } } } --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list