0

In Elisp, I want to insert the contents of the "gazonk" JSON block into a variable.

#+name: gazonk
#+begin_src json
{
  xyzzy "
}
#+end_src

, but I just get "End of file during parsing"

#+BEGIN_SRC elisp :noweb yes
(setq example-data "<<gazonk>>")
#+END_SRC

Obviously, it's not valid JSON, but I want to insert the verbatim contents;)

EDIT: Here is a better example:

Here's valid JSON

#+name: gazonk
#+begin_src json
{
  "GivenName" : "Mortimer",
  "SurName" : "Smith",
  "NameSuffixText" : "Sr",
  "PreferredName" : "Morty",
}
#+end_src

Here's valid JSON, but enclosed, so not really valid;)

#+name: gazonk_enclosed
#+begin_src json
"
{
  "GivenName" : "Mortimer",
  "SurName" : "Smith",
  "NameSuffixText" : "Sr",
  "PreferredName" : "Morty",
}
"
#+end_src

This doesn't work with valid json

#+BEGIN_SRC elisp :results verbatim drawer :noweb yes
  (setq data <<gazonk>>)
#+END_SRC

, but this works

#+BEGIN_SRC elisp :results verbatim drawer :noweb yes
  (setq data <<gazonk_enclosed>>)
#+END_SRC
Jason Hunter
  • 519
  • 2
  • 9
  • How are you evaluating JSON blocks exactly? – NickD Aug 12 '23 at 03:24
  • You seem to have loaded some Org babel library for JSON: when I try to evaluate a JSON source code block, I get an error: `No babel-execute function for json!`. And what works for you does not work for me. So can you please answer the question in my previous comment? – NickD Aug 12 '23 at 16:45
  • 1
    The problem is I'm not sure I understand. Blocks with JSON and XML are not evaluated. At least, I'm not evaluating them for now. I want to include the verbatim contents of a JSON or XML block into a variable, cause I'm using this JSON for example as a body in a curl request. – Jason Hunter Aug 12 '23 at 17:37
  • You are right - I think there is a bug with `:noweb-prefix` . E.g. I tried doing the multiline example towards the bottom of the page in [Noweb Reference Syntax](https://orgmode.org/manual/Noweb-Reference-Syntax.html) and I get no joy: `C-c C-v C-v` does not show anything different with or without the :noweb-prefix` header (although you should try setting it to `no` and see if that works for you - it may be version dependent). However even with that fixed, I don't think there is a way to escape the inner double quotes, so that Lisp can parse the string properly. – NickD Aug 13 '23 at 18:13
  • Can I somehow create a new block of any kind, where I quote the json block, before I noweb it into something else?;) – Jason Hunter Aug 14 '23 at 07:21

0 Answers0