emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Ag Ibragimov <agzam.ibragimov@gmail.com>
Cc: org-mode-email <emacs-orgmode@gnu.org>
Subject: Re: Feature request: results type json
Date: Wed, 28 Mar 2018 15:30:14 -0700	[thread overview]
Message-ID: <CAJ51ETrKKQzn0PwOJ_ssN+F1YhUOGPEcowwbkDHLUQeLUB1-fA@mail.gmail.com> (raw)
In-Reply-To: <CAJZi2B0P7xu++HGeF7A4qgOORqjkJaFbQn9w+pYiNY1tcQjTpg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2288 bytes --]

If you can get ob-sql to output data in tabular form (if it is not nested)
you can do something like this:

#+name: tabular
#+BEGIN_SRC python :results value
d = [['type', 'test'], ['format', 'json']]
return d
#+END_SRC

#+RESULTS: tabular
| type   | test |
| format | json |

#+BEGIN_SRC emacs-lisp :var data=tabular :wrap json
(json-encode data)
#+END_SRC

#+RESULTS:
#+BEGIN_json
{"type":["test"],"format":["json"]}
#+END_json

If the data is nested, then you can see if there is a way to output a lisp
readable string:

#+name: my-data
#+BEGIN_SRC python :results output
print('((type . test) (format . json))')
#+END_SRC

#+RESULTS: my-data
: ((type . test) (format . json))



#+BEGIN_SRC emacs-lisp :var data=my-data :wrap json
(json-encode (read data))
#+END_SRC

#+RESULTS:
#+BEGIN_json
{"type":"test","format":"json"}
#+END_json



John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu


On Wed, Mar 28, 2018 at 2:19 PM, <agzam.ibragimov@gmail.com> wrote:

> Hmm, it works for emacs-lisp, however I specifically wanted to use it with
> ob-sql, and can't find a way.
>
> On Wed, Mar 28, 2018 at 2:05 PM John Kitchin <jkitchin@andrew.cmu.edu>
> wrote:
>
>> Does this do what you want:
>>
>> #+BEGIN_SRC emacs-lisp :wrap json
>> (json-encode '((type . "text")))
>> #+END_SRC
>>
>> #+RESULTS:
>> #+BEGIN_json
>> {"type":"text"}
>> #+END_json
>>
>> John
>>
>> -----------------------------------
>> Professor John Kitchin
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803 <(412)%20268-7803>
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu
>>
>>
>> On Wed, Mar 28, 2018 at 1:42 PM, Ag Ibragimov <agzam.ibragimov@gmail.com>
>> wrote:
>>
>>>
>>> Sorry, I don't know the best medium to convey ideas and I'm afraid not
>>> qualified (familiar with org-mode codebase) to submit a PR for this.
>>> I wonder how difficult would be to
>>> add the possibility to have babel src block results to be rendered as
>>> json?
>>> Basically a new result type https://orgmode.org/manual/
>>> results.html#results
>>>
>>> Thank you.
>>>
>>>
>>

[-- Attachment #2: Type: text/html, Size: 4661 bytes --]

  reply	other threads:[~2018-03-28 22:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 20:42 Feature request: results type json Ag Ibragimov
2018-03-28 21:05 ` John Kitchin
2018-03-28 21:19   ` agzam.ibragimov
2018-03-28 22:30     ` John Kitchin [this message]
2018-03-29  3:44       ` stardiviner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJ51ETrKKQzn0PwOJ_ssN+F1YhUOGPEcowwbkDHLUQeLUB1-fA@mail.gmail.com \
    --to=jkitchin@andrew.cmu.edu \
    --cc=agzam.ibragimov@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).