Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:select with jq prints a newline, by default #43

Open
bhanuvrat opened this issue Feb 23, 2019 · 2 comments
Open

:select with jq prints a newline, by default #43

bhanuvrat opened this issue Feb 23, 2019 · 2 comments

Comments

@bhanuvrat
Copy link

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

@isamert
Copy link

isamert commented May 25, 2019

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*

@nfedyashev
Copy link

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

ag91 added a commit to ag91/ob-http that referenced this issue Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants