emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Feature request: results type json


From: John Kitchin
Subject: Re: [O] Feature request: results type json
Date: Wed, 28 Mar 2018 15:30:14 -0700

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="" :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="" :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

On Wed, Mar 28, 2018 at 2:19 PM, <address@hidden> 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 <address@hidden> 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

On Wed, Mar 28, 2018 at 1:42 PM, Ag Ibragimov <address@hidden> 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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]