all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Parse a field in JSON given a path to the field
@ 2021-11-11 18:42 Husain Alshehhi
  2021-11-13 13:15 ` Andreas Röhler
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Husain Alshehhi @ 2021-11-11 18:42 UTC (permalink / raw)
  To: help-gnu-emacs

Does emacs provide a function that can return a path from a JSON object? I find something like this useful if I want a field from a nested, large JSON. Here is an example of a JSON string

,----
| {
| "field" : {
|   "field1" : {
|     "field2" : {
|       "field3" : "value"
|     }
|   }
| }
`----

I do something like:

,----
| ;; assume that the value is in json-string
| (let ((json (json-parse json-string))
|       (field (gethash "field" json))
|       (field1 (gethash "field1" field))
|       (field2 (gethash "field2" field1))
|       (field3 (gethash "field3" field2)))
|   ;; process field3
|   )
`----

I wonder if there is something like

,----
| (let ((field3 (json-parse-path "field/field1/field2/field3" json-string)))
|   ;; process field3
|   )
`----




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-01-26 22:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-11 18:42 Parse a field in JSON given a path to the field Husain Alshehhi
2021-11-13 13:15 ` Andreas Röhler
2021-11-13 14:08 ` Yuri Khan
2022-01-26 22:05 ` Tim Landscheidt
2022-01-26 22:19   ` 2QdxY4RzWzUUiLuE

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.