reddit / emacs

What libraries or functions, internal or external, does Elisp use to extract fields from JSON?

vfclists · 2022-12-21 23:07
Does Emacs have good libraries for extracting fields from JSON values? Are there some libraries which demonstrate good working examples of these?
phr46 · 2022-12-21 23:35
Emacs comes with a JSON parsing library: [Parsing JSON](https://www.gnu.org/software/emacs/manual/html_node/elisp/Parsing-JSON.html) I don't know a good place for examples but to start you off, json-parse-string parses JSON from a string into an elisp hash table, which you can access with gethash: (gethash "hello" (json-parse-string "{\"hello\": \"world\"}")) -> "world" [Hash Access](https://www.gnu.org/software/emacs/manual/html_node/elisp/Hash-Access.html)
sebhoagie · 2022-12-22 00:34
You can also change the type of object you get back from hash-table to alist, and then use the wonderful get-alist macro the navigate the file contents. This is good for smaller JSON, the bigger what you are parsing the more you benefit from the faster hash-tables.
vfclists · 2022-12-24 13:05
I have had a go at this and it is all good.