From nobody Wed Feb 10 23:04:33 2021 Authentication-Results: mail-b.sr.ht; dkim=none Received: from mail.nullprogram.com (mail.nullprogram.com [192.241.191.137]) by mail-b.sr.ht (Postfix) with ESMTPS id 0671D11F008 for <~skeeto/public-inbox@lists.sr.ht>; Wed, 10 Feb 2021 23:04:32 +0000 (UTC) Received: from nullprogram.com (localhost [127.0.0.1]) by mail.nullprogram.com (Postfix) with ESMTPS id 8CDBFC70F0; Wed, 10 Feb 2021 18:04:32 -0500 (EST) Date: Wed, 10 Feb 2021 18:04:31 -0500 From: Christopher Wellons To: Michael Cc: ~skeeto/public-inbox@lists.sr.ht Subject: Re: Options for Structured Data in Emacs Lisp Message-ID: <20210210230431.nbp5ejpj6dkosn7h@nullprogram.com> References: <87zh0bc2gn.fsf@runbox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <87zh0bc2gn.fsf@runbox.com> User-Agent: NeoMutt/20170113 (1.7.2) You can reflect cl-defstruct to convert records to plists. For instance: (cl-defstruct poi name category latitude longitude) (defun struct-to-plist (struct) (cl-loop for i upfrom 1 for (slot . _) in (cdr (cl-struct-slot-info (type-of struct))) collect (intern (concat ":" (symbol-name slot))) collect (aref struct i))) Then, say, convert to JSON: (json-encode (struct-to-plist #s(poi "Grand Canyon" natural 36.3 -112.6))) ;; => { ;; "name": "Grand Canyon", ;; "category": "natural", ;; "latitude": 36.3, ;; "longitude": -112.6 ;; }