From owner-freebsd-hackers@freebsd.org Sun Sep 9 14:10:05 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8BE7A1095915 for ; Sun, 9 Sep 2018 14:10:05 +0000 (UTC) (envelope-from churchers@gmail.com) Received: from mail-vk1-xa29.google.com (mail-vk1-xa29.google.com [IPv6:2607:f8b0:4864:20::a29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2ACB573FB1 for ; Sun, 9 Sep 2018 14:10:05 +0000 (UTC) (envelope-from churchers@gmail.com) Received: by mail-vk1-xa29.google.com with SMTP id h200-v6so2436949vke.5 for ; Sun, 09 Sep 2018 07:10:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=9DEQscg7gz8bOH4pgylb9XeZAlIyncgJPBPxyEUShug=; b=HeWtcGtPiDSJqXX0IckwesVFZO4yzQEPazJh6c+tIibqzptSy/qIdTW0+ZNQww2uGf gY6ws2bYfGovbJpBcCHMyD8/T9m8CHXnKftvj7pMkSZY5GzeMzVIogBMcSvoWbpTRjks cnhrLUC+vxM6HHdqmcYGj3GEljDEezT3or8I23KOtA/hm+zk7wKQNcLeGaZT6VGM5YnE 6v5f0ItLiUpN/wGFRnpDMuii/MvPpGto8HLAqDWUvtxaar1PxB7xUm5P6ZaDaMcfcz/8 5Ng6gMbRmbGGRv+/hHjE4vNrqV3BKlLl7lD0PB4u/qGZmj1u4ZyboZC/Q0ruAYXlnZd9 ZrgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=9DEQscg7gz8bOH4pgylb9XeZAlIyncgJPBPxyEUShug=; b=bimShaP+3nXVm1DEcAHOeZ4/5+8xkqrJEftKhJkRjyigKWThR0AK8Sb7giUUQWwR2h jhzUao9qITn5Gtps0PdLp+iG2CfuZVPXNlkl/jf3CeOpHeKN4o3lAo+J/FOjwij+jf7j FK9Jd9tYNA7sedTrJx7zlcolFg1DNKIudqRmhaOfTyz943gHEz4mV5Z2iHSr1UE11SfJ 6TXKXBh1fc8t8l8oGijbJHTyfatbpBeZ1D0dTirmIlT820CtmwBYuFZKkOeziciH+Ho1 iqgZXIpSaSSuVqmk1EGAhTglhPGpSR0nGADvEyKsTvtESBZML2tnNyu3XwVFkSwTTCzg kKxg== X-Gm-Message-State: APzg51BtpTByNS3TRbEFuGdHAoJJrkoES/IcSJjXAYV6c8DRR0Imr/Fa Pr29BNP+4gMzwgv/+p5K+TXi3kwAQ5Kx+hAmIkKKig== X-Google-Smtp-Source: ANB0Vdb3bKRJKkEXkXskm/lCw9hKf/uzwe8qQOIBOwdRUp2QqAXr5vu9/Um54fgkmnqlkf/qXxMw5j4+/kNPDlKKR+o= X-Received: by 2002:a1f:2047:: with SMTP id g68-v6mr5254322vkg.103.1536502204493; Sun, 09 Sep 2018 07:10:04 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Matt Churchyard Date: Sun, 9 Sep 2018 15:10:09 +0100 Message-ID: Subject: Fwd: Getting valid JSON output with xo(1) To: freebsd-hackers@freebsd.org X-Mailman-Approved-At: Sun, 09 Sep 2018 14:23:24 +0000 Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.27 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Sep 2018 14:10:05 -0000 Hi Stefan, I did include the commands used to generate the sample output in my first message. I am using the xo(1) utility, not libxo directly. I did mention this might not be the right list (you've obviously assumed I'm directly using libxo), but it does seem to me this is more an issue with the xo utility, rather than just a usage error. I've since looked further into the libxo documentation, and as you suggest, it does seem that I need to be using the xo_open_list/xo_close_list functions to generate the right output. However, these are not exposed via xo(1). The documentation for xo_open_list describes how it is used to create lists of individual entities, whereas the "l" modifier (which is all I can access via xo(1)) creates "leaf lists", which are only for single values. As such, it seems there's a big hole in the functionality of xo(1), meaning it can only really be used to create very simple JSON documents. As I mentioned in my first message, it looks like xo(1) could do with some way to open/close lists, similar to the --open/--close options, and a way to specify that a single call should be output as a part of a list. Matt On Sun, Sep 9, 2018 at 10:29 AM Stefan Esser wrote: > Am 08.09.18 um 15:41 schrieb Matt Churchyard: > > Hello, > > > > Sorry if this is the wrong list, I wasn't sure which was the most > > appropriate. > > > > I've been asked to look at generating machine output from vm-bhyve using > > xo(1), and though it would be an interesting task. However, I'm coming > > across a few issues getting valid output. I've reduced my code down to > the > > following example - > > > > xo -pX --open bhyve/machines > > xo -pX --depth 2 --wrap machine "{:name},{:memory}" test1 2GB > > xo -pX --depth 2 --wrap machine "{:name},{:memory}" test2 4GB > > xo -pX --close bhyve/machines > > > > This produces the following XML output which looks good - > > > > > > > > > > test1 > > 2GB > > > > > > test2 > > 4GB > > > > > > > > > > If I choose HTML output I get the following invalid output which is > missing > > closing tags. > > > >
> >
test1
> >
,
> >
2GB
> >
> >
test2
> >
,
> >
4GB
> > > > This can be fixed by adding "\n" to the end of the format lines, which > may > > be required, but it seems strange that I can so easily generate broken > > output. I'm not too bothered about HTML though as it seems fairly > useless, > > JSON is my biggest issue - > It would be a lot easier to help if you posted a (stripped down) version of > the code used to generate this output. > > You are not correctly using the list functions, and thus the outer lists > are > not closed. I had suggested a better syntax and semantics for these > functions > to automatically take care of such cases, but they were rejected by the > main > libxo author. > > Every xo_open_list() must be matched by a matching xo_close_list() and you > may need to use another type (list, container, instance) than you currently > do. > > Did you run xolint to test your usage of xo functions? > > Regards, STefan >