ob-http icon indicating copy to clipboard operation
ob-http copied to clipboard

:select with jq prints a newline, by default

Open bhanuvrat opened this issue 6 years ago • 2 comments

jq -j would strip the newline it adds. when I tried to construct a url like

#+NAME: get_user_id
#+BEGIN_SRC http :pretty :var auth_token=login :select .results | .[0] | .id
GET /api/users?search=c
Authorization: Token ${auth_token}
#+END_src

#+RESULTS: get_user_id
: 1bc184b8-b41d-4198-99ae-e69a4ad112a6

GET /api/users/${id}

#+NAME: get_record_of_one_user
#+HEADER: :var auth_token=login 
#+HEADER: :var id=strip(get_user_id)
#+HEADER: :var blah=1
#+BEGIN_SRC http :pretty 
GET http://httpbin.org/anything/${id}
Authorization: Token ${auth_token}

#+END_SRC

the authorization header went to body because id brought a newline along

bhanuvrat avatar Feb 23 '19 15:02 bhanuvrat

I had problems related to this too. This project seems inactive. Meanwhile I advise simply changing all jq -r strings with jq -j in ob-http.el file. If you installed the package trough melpa, this will take care of it:

sed -i 's/jq -r/jq -j/g' ~/.emacs.d/elpa/ob-http-*/ob-http.el*

isamert avatar May 25 '19 16:05 isamert

I decided not to patch the source and made a little wrapper org-babel block that truncates new line characters returned from .select jq block.

#+NAME: valid-entry-uuid
#+HEADER: :var uuid=raw-entry-uuid
#+begin_src emacs-lisp
(replace-regexp-in-string "\n+" "" uuid)
#+end_src

HTH

nfedyashev avatar Apr 08 '23 15:04 nfedyashev