help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Parse a field in JSON given a path to the field


From: Husain Alshehhi
Subject: Parse a field in JSON given a path to the field
Date: Thu, 11 Nov 2021 18:42:51 +0000

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
|   )
`----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]