* Feature request: results type json @ 2018-03-28 20:42 Ag Ibragimov 2018-03-28 21:05 ` John Kitchin 0 siblings, 1 reply; 5+ messages in thread From: Ag Ibragimov @ 2018-03-28 20:42 UTC (permalink / raw) To: emacs-orgmode 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. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Feature request: results type json 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 0 siblings, 1 reply; 5+ messages in thread From: John Kitchin @ 2018-03-28 21:05 UTC (permalink / raw) To: Ag Ibragimov; +Cc: org-mode-email [-- Attachment #1: Type: text/plain, Size: 833 bytes --] 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 @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: 1680 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Feature request: results type json 2018-03-28 21:05 ` John Kitchin @ 2018-03-28 21:19 ` agzam.ibragimov 2018-03-28 22:30 ` John Kitchin 0 siblings, 1 reply; 5+ messages in thread From: agzam.ibragimov @ 2018-03-28 21:19 UTC (permalink / raw) To: John Kitchin; +Cc: org-mode-email [-- Attachment #1: Type: text/plain, Size: 1097 bytes --] 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: 2236 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Feature request: results type json 2018-03-28 21:19 ` agzam.ibragimov @ 2018-03-28 22:30 ` John Kitchin 2018-03-29 3:44 ` stardiviner 0 siblings, 1 reply; 5+ messages in thread From: John Kitchin @ 2018-03-28 22:30 UTC (permalink / raw) To: Ag Ibragimov; +Cc: org-mode-email [-- 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 --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Feature request: results type json 2018-03-28 22:30 ` John Kitchin @ 2018-03-29 3:44 ` stardiviner 0 siblings, 0 replies; 5+ messages in thread From: stardiviner @ 2018-03-29 3:44 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 3452 bytes --] You can wrap result value into another language src block like this: #+begin_src ruby :results code :wrap src shell puts "echo 'hello'" #+end_src #+RESULTS: #+begin_src shell echo 'hello' #+end_src Same for JSON by changed `:wrap src shell` into `wrap json`. But you need the value is JSON. Isaw you mentioned want ob-sql support JSON return type. I guess it need to be implemented in ob-sql.Or you can use `:post` to convert result to JSON. Or use `advice-add` to add a function to convert result to JSON. On 03/29/2018 06:30 AM, John Kitchin wrote: > 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 > <mailto: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 <mailto: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 <tel:%28412%29%20268-7803> > @johnkitchin > http://kitchingroup.cheme.cmu.edu > <http://kitchingroup.cheme.cmu.edu> > > > On Wed, Mar 28, 2018 at 1:42 PM, Ag Ibragimov > <agzam.ibragimov@gmail.com <mailto: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 > <https://orgmode.org/manual/results.html#results> > > Thank you. > > > [-- Attachment #2: Type: text/html, Size: 10526 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-03-29 3:44 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 2018-03-29 3:44 ` stardiviner
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.