Hot answers tagged

13 votes
Accepted

Accessing JSON data in elisp

I've taken the liberty of adjusting your code appropriately: (require 'json) (let* ((json-object-type 'hash-table) (json-array-type 'list) (json-key-type 'string) (json (json-...
user avatar
  • 21.1k
9 votes

Code-folding extensions for json

There are more folding options for Emacs: http://wikemacs.org/wiki/Folding#Yafolding and Yafolding looks like the best for your case since it is based on indentation. It also includes a nice interface ...
user avatar
  • 1,051
6 votes

How to iterate over JSON list and select one element

You can instruct json-read-from-string to parse JSON arrays as elisp lists by let binding json-array-type to list like so (let ((json-object-type 'plist) (json-array-type 'list)) (setq mylist ...
user avatar
  • 7,318
5 votes

org export json

Here is a lightly adapted version of the export code you were using. The strategy I used to get selective export is to make a temporary org-file using org-map-entries and the match argument for it to ...
user avatar
  • 11.1k
4 votes

How to encode empty json object in elisp?

It's unlikely that there will be a solution here that will satisfy every user of the json package, since the problem is that elisp and json have differing semantics. In Lisp, the empty list and the ...
user avatar
  • 12.2k
4 votes
Accepted

How do i create a nested list from a json data?

We can get 'more or less' the result that you want using the following function: (defun json-format (obj) (when obj (cons (let ((rest (cdr (car obj)))) (if (vectorp rest) ...
user avatar
  • 2,330
3 votes
Accepted

How do you get data by key from a json list?

Cute. Take a look at the beginning of the alist again: ((1 . [((id . 2) (attribute . salutation)… It looks like the key is a number, so I tried that (assoc 1 tester) nil It doesn't have any ...
user avatar
  • 12.2k
3 votes

Code-folding extensions for json

Use emacs' hideshow. You can keep your cursor anywhere & to hide blocks 'n' level below it, use the command C-c @ C-l Here, n is a numeric prefix argument that gets set by pressing C-u 1 RET ...
user avatar
  • 1,897
3 votes

json-mode hook not being run

add-hook does not take a mode symbol as its first parameter; it takes a symbol for a hook variable. Replace 'json-mode with 'json-mode-hook and you'll be all set. Note the differences between the ...
user avatar
2 votes
Accepted

hs-minor-mode keybindings are undefined or bring up help window

So I realized my mistake shortly after submitting my question, and rather than deleting it I thought I'd answer in case someone else ends up here. Many of the keybindings on the Hide Show page are ...
user avatar
2 votes

JSON major mode complaining about valid JSON file

I have the same problem. Turns out I'm using js2-mode as minor-mode for js-mode (add-hook 'js-mode-hook 'js2-minor-mode) Everything is ok after remove above code from my .emacs.el Another option is ...
user avatar
  • 305
2 votes
Accepted

Emacs, pretty print but showing spaces and \n

The following lisp code modifies org-babel-variable-assignments:plantuml. If you prefix a variable of a plantuml source block with json: newlines escaped with the character ?\\ are not stripped from ...
user avatar
  • 30.5k
2 votes

How do I filter an alist to just the properties I care about?

Recursion for the win. (defun json-filter-paths (json paths) (mapcar (lambda (elt) (if (consp elt) (cons (car elt) (json-filter-paths (cdr (assoc (...
user avatar
  • 3,276
2 votes

How to make Emacs edit JSON data in `json-mode`?

Install json-mode might be the simplest. In my set up (I use straight.el) simply (use-package json-mode)
user avatar
  • 758
2 votes

Why am I getting this error, saying that a comma is not a function?

I probably don't understand your problem. Your question isn't very clear (what calls to message are you using?). But if I do understand what you're trying to do, it pretty much amounts to this: You ...
user avatar
  • 70.3k
2 votes

Why am I getting this error, saying that a comma is not a function?

You can get the symbol name with symbol-name, which returns a string, and then convert the string to a number: (string-to-number (symbol-name '\1)) ==> 1
user avatar
  • 20.6k
2 votes
Accepted

Insert json or XML blocks in org mode

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 ...
user avatar
  • 20.5k
2 votes
Accepted

How can I work around json-encode error with key "t"

This is a well-known long-standing bug in json.el that has been fixed in the latest development version of Emacs (what will be released in the future as Emacs 28): https://bugs.gnu.org/42545 If you ...
user avatar
  • 11.4k
1 vote
Accepted

Manage JSON (comments) with org literate programming and tangle

Here is a way to do this with literate programming in org. #+BEGIN_SRC json :tangle config.json {"key1": "value", #+END_SRC For key2 I prefer 0 instead of 1 #+BEGIN_SRC json :...
user avatar
  • 11.1k
1 vote
Accepted

Json - get count of elements

You can use json-read function json-read is a compiled Lisp function in json.el. Parse and return the JSON object following point. Advances point just past JSON object. like this (save-...
user avatar
  • 2,185
1 vote
Accepted

Org export to html

Your configuration, (add-hook 'js-mode-hook 'json-pretty-print-buffer-ordered) means the function json-pretty-print-buffer-ordered will run anytime js-mode is started. This is probably not what you ...
user avatar
  • 20.5k
1 vote

how to generate dynamic json data with emacs (macros)?

You can just make a list and then encode it as json like this: (require 'cl-lib) (require 'json) (json-encode (cl-loop for i to 100 collect (list (cons 'id i) (cons 'text "...")))) That gives me ...
user avatar
  • 11.1k
1 vote
Accepted

JSON file folding and step-by-step unfolding

The json-navigator Emacs package displays any JSON document in a tree-like structure. It uses the hierarchy package.
user avatar
1 vote

JSON file folding and step-by-step unfolding

You should try hs-hide-level with numeric prefix argument. The argument specifies the sub-level of the blocks to hide relative to the block you are in. If you want to have some kind of current level ...
user avatar
  • 30.5k
1 vote

json-readtable-error during org-capture

I received the exact same error on a fresh Ubuntu install using Emacs 26.3. In my case it was related to the ob-ipython packet, which requires ipython and jupyter to be installed, which I hadn't come ...
user avatar
  • 133
1 vote

json-readtable-error during org-capture

For anyone who is curious, adding the following code in the init.el solved the issue. Turns out Rmacs was not being able to load JSON setup because it was looking in the wrong folder. I also had to ...
user avatar
1 vote

Is there a way to check whether or not a string is valid json?

C-x my-validate-json-or-js-expression validate the current buffer or selected region as json. The only requirement is you need install js2-mode. (No, you don't need setup js2-mode. My code works out ...
user avatar
  • 4,631
1 vote

Outline editing, like org-mode, for JSON

Emacs comes with hs-minor-mode which can be used selectively hide/show code and comment blocks in several languages, including JavaScript. By default this will let you hide and show JSON blocks ...
user avatar
  • 717

Only top scored, non community-wiki answers of a minimum length are eligible