aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-07-09 19:41:06 +0200
committerLars Ingebrigtsen2019-07-09 19:41:11 +0200
commit7c317c835ad506ec0e1029836b19fbbca9e0ae3b (patch)
tree0844ada91fda2afe2c9885a0c24b6948fef3d976
parent75af25cba01adbc7ea98d933a1bc7a8b5ffec7f1 (diff)
downloademacs-7c317c835ad506ec0e1029836b19fbbca9e0ae3b.tar.gz
emacs-7c317c835ad506ec0e1029836b19fbbca9e0ae3b.zip
Clarify json-read and json-encode parameters and return values
* lisp/json.el (json-read): Try to clarify what's returned (bug#34242). (json-encode): Refer to `json-read' about what the input is and say what error is signalled.
-rw-r--r--lisp/json.el20
1 files changed, 18 insertions, 2 deletions
diff --git a/lisp/json.el b/lisp/json.el
index 44b3c33df7c..d3655a0f26c 100644
--- a/lisp/json.el
+++ b/lisp/json.el
@@ -691,7 +691,19 @@ become JSON objects."
691 691
692(defun json-read () 692(defun json-read ()
693 "Parse and return the JSON object following point. 693 "Parse and return the JSON object following point.
694Advances point just past JSON object." 694Advances point just past JSON object.
695
696If called with the following JSON after point
697
698 {\"a\": [1, 2, {\"c\": false}],
699 \"b\": \"foo\"}
700
701you will get the following structure returned:
702
703 ((a .
704 [1 2
705 ((c . :json-false))])
706 (b . \"foo\"))"
695 (json-skip-whitespace) 707 (json-skip-whitespace)
696 (let ((char (json-peek))) 708 (let ((char (json-peek)))
697 (if (zerop char) 709 (if (zerop char)
@@ -719,7 +731,11 @@ Advances point just past JSON object."
719;;; JSON encoder 731;;; JSON encoder
720 732
721(defun json-encode (object) 733(defun json-encode (object)
722 "Return a JSON representation of OBJECT as a string." 734 "Return a JSON representation of OBJECT as a string.
735
736OBJECT should have a structure like one returned by `json-read'.
737If an error is detected during encoding, an error based on
738`json-error' is signalled."
723 (cond ((memq object (list t json-null json-false)) 739 (cond ((memq object (list t json-null json-false))
724 (json-encode-keyword object)) 740 (json-encode-keyword object))
725 ((stringp object) (json-encode-string object)) 741 ((stringp object) (json-encode-string object))