JSON (JavaScript Objecte Notation) is a lightweight data-interchange format.
It is based on a subset of the JavaScript Programming Language,Standard ECMA-262 3rd Edition - December 1999.
JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, Lisp, and many others.
In lisp exists a high performance JSON encoder and decoder, Called Jonathan Currently support: SBCL, CCL.
Example with Jonathan JSON
;; JSON ENCODER
(defclass user ()
((user-id :accessor user-id :type integer :initarg :user-id)
(user-name :accessor user-name :type string :initarg :user-name)
(user-lastname :accessor user-lastname :type string :initarg :user-lastname)
(user-email :accessor user-email :type string :initarg :user-email)))
(defmethod %to-json ((obj user))
(with-object
(write-key-value "userid" (slot-value obj 'user-id))
(write-key-value "username" (slot-value obj 'user-name))
(write-key-value "userlastname" (slot-value obj 'user-lastname))
(write-key-value "useremail" (slot-value obj 'user-email))))
(defparameter *JSON-ENCODER* nil)
(setf *JSON-ENCODER* (to-json (make-instance 'user
:user-id 1
:user-name "Jesus Manuel"
:user-lastname "Castro Carcia"
:user-email "jesus@ikkiware.com")))
> *JSON-ENCODER*
"{\"userid\":1,\"username\":\"Jesus Manuel\",\"userlastname\":\"Castro Garcia\",\"useremail\":\"jesus@ikkiware.com\"}"
;; -----------------------------------------------------------------------------------------------------------------
;; DECODER JSON
(defun DECODER-JSON (json-encoder)
"Return json-encoder as list asociative"
(jonathan:parse json-encoder :as :alist))
> (DECODER-JSON *JSON-ENCODER*)
(("useremail" . "jesus@ikkiware.com") ("userlastname" . "Castro Carcia")
("username" . "Jesus Manuel") ("userid" . 1))
OR
> (REVERSE (DECODER-JSON *JSON-ENCODER*))
(("userid" . 1) ("username" . "Jesus Manuel")
("userlastname" . "Castro Carcia") ("useremail" . "jesus@ikkiware.com"))
#json #JSON #JsonEncoder #JsonDecoder #JAVASCRIPT #JavaScript #JavascriptObjectNotation #Encoder #Decoder #Lisp #Jonathan #JonathanLisp #JsonJonathan