1

I often have to insert blocks of json or XML code into my org documents. What is the preferred way of doing so?

I see that for the standard:

#+BEGIN_SRC 
...
#+END_SRC

... there is no json or xml in the list of supported languages: https://orgmode.org/manual/Languages.html

And the same goes for babel languages: https://orgmode.org/worg/org-contrib/babel/languages/index.html

Thanks!

1 Answer 1

2

Org babel "Supported languages" are languages that you can evaluate/execute directly from an orgmode code block. I don't think JSON and XML are executable languages anywhere, so you don't need special support for them. You can still use src blocks, and if there's an Emacs mode for editing the language, it will apply the formatting to the code.

If you have JSON mode installed, you could use that. I don't, but JSON is close enough to Javascript that it produces reasonable formatting:

#+begin_src js
  {
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 27,
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ],
  "children": [],
  "spouse": null
}
#+end_src

Which appears like this:

enter image description here

xml files are edited in the built-in mode nxml by default, so you don't need to add anything to use it:

#+begin_src xml
  <note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
  </note>
#+end_src

Which is formatted as:

enter image description here

1
  • Actually, all supported languages in Babel mode are not executable languages. You have languages for define blocks and UML diagrams, which are not executable. But when you execute them, they generate PNG pictures that can be included in the document. But yes, I would use #+begin_src xml and #+end_src as you have.
    – Anders
    Jan 27 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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