1

I'm trying to define some data in json file and use the file name in another bloc as command parameter. Something like that:

The data:
#+BEGIN_SRC json
{
  "Foo": "Bar"
}
#+END_SRC

... and the script
#+BEGIN_SRC json
do_something_with_json $the_data
#+END_SRC

Is it possible?

1

1 Answer 1

1

Read (org) var for the capabilities. As far as I know, you can't reference a src block without run it, but you can reference a literal example, for example, you have put your json data into an EXAMPLE block

#+NAME: json_data
#+BEGIN_EXAMPLE
{
  "method": "+",
  "params": [1, 2, 3]
}
#+END_EXAMPLE

then you can reference the json data via its NAME

#+BEGIN_SRC sh :var x=json_data
echo $x | jq .method
#+END_SRC

#+RESULTS:
: +

here is another use

#+BEGIN_SRC emacs-lisp :var x=json_data
(let-alist (let ((json-array-type 'list))
             (json-read-from-string x))
  (apply (intern .method) .params))
#+END_SRC

#+RESULTS:
: 6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.